{"record":{"id":"32aa615bdc000afc","repo":"antonmedv/fx","slug":"invalid-unicode-escape-sequence-u-s-c","errorCode":null,"errorMessage":"Invalid Unicode escape sequence '\\u%s%c'","messagePattern":"Invalid Unicode escape sequence '\\\\u(.+?)%c'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/json.go","lineNumber":221,"sourceCode":"\t\tLineNumber: p.lineNumberPlusPlus(),\n\t}\n}\n\nfunc (p *JsonParser) scanString() string {\n\tstart := p.end - 1\n\tp.next()\n\tescaped := false\n\tfor {\n\t\tif escaped {\n\t\t\tescaped = false\n\t\t\tif p.strict {\n\t\t\t\tswitch p.char {\n\t\t\t\tcase 'u':\n\t\t\t\t\tvar s string\n\t\t\t\t\tfor i := 0; i < 4; i++ {\n\t\t\t\t\t\tp.next()\n\t\t\t\t\t\tif !utils.IsHexDigit(p.char) {\n\t\t\t\t\t\t\tpanic(fmt.Sprintf(\"Invalid Unicode escape sequence '\\\\u%s%c'\", s, p.char))\n\t\t\t\t\t\t}\n\t\t\t\t\t\ts += string(p.char)\n\t\t\t\t\t}\n\t\t\t\t\t_, err := strconv.ParseInt(s, 16, 32)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tpanic(fmt.Sprintf(\"Invalid Unicode escape sequence '\\\\u%s'\", s))\n\t\t\t\t\t}\n\t\t\t\tcase '\"', '\\\\', '/', 'b', 'f', 'n', 'r', 't':\n\t\t\t\tdefault:\n\t\t\t\t\tpanic(fmt.Sprintf(\"Invalid escape sequence '\\\\%c'\", p.char))\n\t\t\t\t}\n\t\t\t}\n\t\t} else if p.char == '\\\\' {\n\t\t\tescaped = true\n\t\t} else if p.char == '\"' {\n\t\t\tbreak\n\t\t} else if p.char == 0 {\n\t\t\tpanic(\"Unexpected end of input in string\")","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/json.go#L203-L239","documentation":"Inside a string literal in strict mode, scanString found a \\u escape whose 4 hex digits are incomplete — the character right after the digits read so far is not a hex digit. The message includes the hex digits collected and the offending character.","triggerScenarios":"Parsing a string containing '\\u12z4', '\\u00', or '\\u' followed by end-of-input/non-hex character while the parser runs in strict mode; called via Parse -> parseString -> scanString.","commonSituations":"Hand-rolled string escaping in generated code, template engines that only partially expand \\uXXXX escapes, copy-paste from sources that mangled unicode escapes, truncated files cutting an escape mid-sequence.","solutions":["Fix the string so every \\u is followed by exactly 4 hex digits (e.g. '\\u0041' instead of '\\uA')","Use the actual character directly in the source (UTF-8 'A') instead of a \\u escape","Escape properly with a JSON encoder (encoding/json Marshal) instead of hand-building escapes","If non-strict semantics suffice, disable strict mode; scanString only validates escapes when p.strict is true"],"exampleFix":"// before\n\"caf\\u00e\"\n// after\n\"caf\\u00e9\"  // or \"café\"","handlingStrategy":"validation","validationCode":"re := regexp.MustCompile(`\\\\\\\\u[0-9a-fA-F]{4}`)\n// ensure every backslash-u in string literals has 4 hex digits\nif strings.Contains(string(b), \"\\\\u\") && !re.Match(b) { return errors.New(\"malformed \\\\u escape\") }","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tif msg, ok := r.(string); ok && strings.Contains(msg, \"Invalid Unicode escape\") {\n\t\t\terr = errors.New(\"input contains malformed \\\\uXXXX escape\")\n\t\t}\n\t}\n}()","preventionTips":["Generate escapes with encoding/json Marshal, never by hand","Regex-audit inputs for \\\\u not followed by 4 hex digits","Keep source files saved as UTF-8 and use literal characters instead of escapes","Test round-trip: Marshal then Unmarshal every generated payload"],"tags":["json","unicode","escape-sequence","strict-mode"],"backgroundTag":"invalid-unicode-escape","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}