{"record":{"id":"89e24413fa9433cc","repo":"dgraph-io/dgraph","slug":"not-a-valid-escape-char-c","errorCode":null,"errorMessage":"Not a valid escape char: '%c'","messagePattern":"Not a valid escape char: '%c'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lex/lexer.go","lineNumber":410,"sourceCode":"\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\n}\n","sourceCodeStart":392,"sourceCodeEnd":420,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/lex/lexer.go#L392-L420","documentation":"Inside LexQuotedString, a backslash starts an escape sequence; the next rune must be one of the lexer's valid escape characters (checked via IsEscChar). If it is not, the lexer rejects the string with this error naming the offending character. Dgraph's lexer supports a limited escape set, so arbitrary \\x sequences or stray backslashes fail.","triggerScenarios":"A string literal in a DQL query or RDF mutation contains '\\\\' followed by a character not in the escape table — e.g. \\x41, \\u0041 (unsupported form), a trailing backslash before the closing quote, or a Windows path like 'C:\\Users\\bob' inserted unescaped.","commonSituations":"Inserting file paths, regexes, or JSON blobs into mutations without escaping; generating queries by string concatenation; copying N-Quads with non-standard escapes.","solutions":["Double the backslash (write \\\\\\\\ in source to mean a literal backslash) or remove the escape","Use only supported escape characters (\\\\\", \\\\\\\\, \\\\n, \\\\t, etc. — see IsEscChar) inside string literals","When embedding JSON, use Dgraph's JSON mutation format instead of hand-escaped N-Quads","Build queries with parameterized/builder libraries instead of string concatenation"],"exampleFix":"// before\n<0x01> <path> \"C:\\Users\\bob\" .\n// after\n<0x01> <path> \"C:\\\\Users\\\\bob\" .","handlingStrategy":"validation","validationCode":"// Validate escapes in string literals: allowed set per lexer IsEscChar\nvar validEsc = map[rune]bool{'n': true, 't': true, 'r': true, '\"': true, '\\\\': true, '\\'': true}\nfunc checkEscapes(s string) error {\n    for i, r := range s {\n        if r == '\\\\' && i+1 < len([]rune(s)) {\n            nxt := []rune(s)[i+1]\n            if !validEsc[nxt] {\n                return fmt.Errorf(\"invalid escape \\\\%c at %d\", nxt, i)\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := mutate(q); err != nil && strings.Contains(err.Error(), \"Not a valid escape char\") {\n    return fmt.Errorf(\"bad escape sequence in literal: %w\", err)\n}","preventionTips":["Double every backslash in paths and regexes inside string literals","Build queries with JSON APIs or builder libraries to avoid manual escaping","Never hand-concatenate user input into N-Quads; sanitize backslashes first"],"tags":["lexer","escape-character","string-literal"],"backgroundTag":"invalid-escape-character","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}