{"record":{"id":"e0176e5d05286ba3","repo":"vitessio/vitess","slug":"unescapeid-err-unexpected-single-backtick-at-posi","errorCode":null,"errorMessage":"UnescapeID err: unexpected single backtick at position %d in '%s'","messagePattern":"UnescapeID err: unexpected single backtick at position (.+?) in '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/sqlescape/ids.go","lineNumber":75,"sourceCode":"// UnescapeID reverses any backticking in the input string by EscapeID.\nfunc UnescapeID(in string) (string, error) {\n\tl := len(in)\n\n\tif l == 0 || in == \"``\" {\n\t\treturn \"\", fmt.Errorf(\"UnescapeID err: invalid input identifier '%s'\", in)\n\t}\n\n\tif l == 1 {\n\t\tif in[0] == '`' {\n\t\t\treturn \"\", errors.New(\"UnescapeID err: invalid input identifier '`'\")\n\t\t}\n\t\treturn in, nil\n\t}\n\n\tfirst, last := in[0], in[l-1]\n\n\tif first == '`' && last != '`' {\n\t\treturn \"\", fmt.Errorf(\"UnescapeID err: unexpected single backtick at position %d in '%s'\", 0, in)\n\t}\n\tif first != '`' && last == '`' {\n\t\treturn \"\", fmt.Errorf(\"UnescapeID err: unexpected single backtick at position %d in '%s'\", l, in)\n\t}\n\tif first != '`' && last != '`' {\n\t\tif idx := strings.IndexByte(in, '`'); idx != -1 {\n\t\t\treturn \"\", fmt.Errorf(\"UnescapeID err: no outer backticks found in the identifier '%s'\", in)\n\t\t}\n\t\treturn in, nil\n\t}\n\n\tin = in[1 : l-1]\n\n\tif found := strings.Contains(in, \"`\"); !found {\n\t\treturn in, nil\n\t}\n\n\tvar buf strings.Builder","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqlescape/ids.go#L57-L93","documentation":"Returned by sqlescape.UnescapeID when a backtick-quoted identifier contains an unexpected single backtick at the given position, i.e. a stray or unpaired backtick inside the identifier.","triggerScenarios":"Calling UnescapeID on a string like \"`tablename\" — opening backtick present, closing one missing.","commonSituations":"String truncation (e.g. log parsing, config splitting on backticks), hand-built identifiers where only one side was quoted, copy-paste errors.","solutions":["Ensure identifiers are escaped/paired with EscapeID rather than hand-built strings","Validate balanced backticks before calling UnescapeID","Trace where the string was truncated and fix the producer"],"exampleFix":"// before\nname, err := sqlescape.UnescapeID(raw)\n// after\nif strings.Count(raw, \"`\")%2 != 0 {\n\treturn fmt.Errorf(\"unbalanced backticks in %q\", raw)\n}\nname, err := sqlescape.UnescapeID(raw)","handlingStrategy":"validation","validationCode":"func balancedBackticks(in string) bool { return strings.Count(in, \"`\")%2 == 0 }","typeGuard":"func isQuotedID(in string) bool { return len(in) >= 2 && in[0] == '`' && in[len(in)-1] == '`' }","tryCatchPattern":"if !isQuotedID(raw) && strings.Contains(raw, \"`\") {\n\treturn fmt.Errorf(\"malformed identifier %q\", raw)\n}\nname, err := sqlescape.UnescapeID(raw)","preventionTips":["Always use sqlescape.EscapeID to produce escaped identifiers","Do not build backticked names by hand or via string splitting","Guard against truncation when storing/transmitting identifiers"],"tags":["go","sql","identifier","parsing"],"backgroundTag":"invalid-identifier","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}