{"record":{"id":"ccc9571d98ab7ec0","repo":"dgraph-io/dgraph","slug":"string-should-start-with-quote","errorCode":null,"errorMessage":"String should start with quote.","messagePattern":"String should start with quote\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lex/lexer.go","lineNumber":400,"sourceCode":"func (l *Lexer) IsEscChar(r rune) bool {\n\tswitch r {\n\tcase 'u', 'v', 't', 'b', 'n', 'r', 'f', '\"', '\\'', '\\\\':\n\t\treturn true\n\t}\n\treturn false\n}\n\n// IsEndOfLine returns true if the rune is a Linefeed or a Carriage return.\nfunc IsEndOfLine(r rune) bool {\n\treturn r == '\\u000A' || r == '\\u000D'\n}\n\n// LexQuotedString properly processes a quoted string (by taking care of escaped characters).\nfunc (l *Lexer) LexQuotedString() error {\n\tl.Backup()\n\tr := l.Next()\n\tif r != quote {\n\t\treturn errors.Errorf(\"String should start with quote.\")\n\t}\n\tfor {\n\t\tr := l.Next()\n\t\tif r == EOF {\n\t\t\treturn errors.Errorf(\"Unexpected end of input.\")\n\t\t}\n\t\tif r == '\\\\' {\n\t\t\tr := l.Next()\n\t\t\tif !l.IsEscChar(r) {\n\t\t\t\treturn errors.Errorf(\"Not a valid escape char: '%c'\", r)\n\t\t\t}\n\t\t\tcontinue // eat the next char\n\t\t}\n\t\tif r == quote {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn nil","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/lex/lexer.go#L382-L418","documentation":"LexQuotedString processes a quoted string literal in the lexer, handling escapes. Before scanning, it backs up and reads one rune; if that rune is not the quote character ('\"'), it means the lexer was invoked at a position that does not start a string. The error guards against internal lexer state machines (lexContent, lexFacets, lexFuncOrArg, lexText) dispatching to string lexing incorrectly, usually due to malformed input.","triggerScenarios":"The lexer's state function hands control to LexQuotedString but the current rune is not a '\"' — e.g. input contains a quote-like construct the dispatcher mispredicted, or custom/embedded lexer usage calls LexQuotedString at a non-quote position.","commonSituations":"Queries or RDF mutations with a lone or misplaced quotation mark, smart quotes (' ' ') pasted from editors or Word, or facet values that start a string incorrectly.","solutions":["Replace smart/curly quotes with straight ASCII double quotes in the query/mutation","Check the position reported by the lexer and remove or correctly open the string literal","Re-encode the input as UTF-8 plain ASCII quotes; some editors autocorrect quotes","If using the lexer package directly, only call LexQuotedString when the previous rune is a quote"],"exampleFix":"// before (curly quote from copy-paste)\n<0x01> <name> “Alice” .\n// after\n<0x01> <name> \"Alice\" .","handlingStrategy":"validation","validationCode":"// Reject quote characters that are not ASCII '\"'\nfunc checkQuotes(s string) error {\n    for i, r := range s {\n        if (r == '\\u201c' || r == '\\u201d' || r == '\\u2018' || r == '\\u2019') {\n            return fmt.Errorf(\"non-ASCII quote at byte %d\", i)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := runQuery(q); err != nil && strings.Contains(err.Error(), \"String should start with quote\") {\n    return fmt.Errorf(\"misplaced quote in query: %w\", err)\n}","preventionTips":["Disable smart-quote autocorrect in editors for DQL/RDF files","Save query files as plain UTF-8 ASCII where possible","Use builder libraries or JSON mutations to avoid manual quoting"],"tags":["lexer","string-literal","quoting"],"backgroundTag":"unterminated-string-literal","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}