{"record":{"id":"7d612ffdee5c714b","repo":"vitessio/vitess","slug":"s-w","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/sqltypes/value.go","lineNumber":994,"sourceCode":"// We do need all characters here, since we do accept\n// escaped double quotes in single quote strings and\n// double quoted strings.\nvar decodeRef = map[byte]byte{\n\t'\\x00': '0',\n\t'\\'':   '\\'',\n\t'\"':    '\"',\n\t'\\b':   'b',\n\t'\\n':   'n',\n\t'\\r':   'r',\n\t'\\t':   't',\n\t26:     'Z', // ctl-Z\n\t'\\\\':   '\\\\',\n}\n\n// BufDecodeStringSQL decodes the string into a strings.Builder\nfunc BufDecodeStringSQL(buf *strings.Builder, val string) error {\n\tif len(val) < 2 || val[0] != '\\'' || val[len(val)-1] != '\\'' {\n\t\treturn fmt.Errorf(\"%s: %w\", val, ErrInvalidEncodedString)\n\t}\n\tin := hack.StringBytes(val[1 : len(val)-1])\n\tidx := 0\n\tfor {\n\t\tif idx >= len(in) {\n\t\t\treturn nil\n\t\t}\n\t\tch := in[idx]\n\t\tif ch == '\\'' {\n\t\t\tidx++\n\t\t\tif idx >= len(in) {\n\t\t\t\treturn fmt.Errorf(\"%s: %w\", val, ErrInvalidEncodedString)\n\t\t\t}\n\t\t\tif in[idx] != '\\'' {\n\t\t\t\treturn fmt.Errorf(\"%s: %w\", val, ErrInvalidEncodedString)\n\t\t\t}\n\t\t\tbuf.WriteByte(ch)\n\t\t\tidx++","sourceCodeStart":976,"sourceCodeEnd":1012,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/sqltypes/value.go#L976-L1012","documentation":"BufDecodeStringSQL decodes a single-quoted SQL string literal into a strings.Builder. If the input is shorter than 2 chars or does not start and end with a single quote, it returns the original value prefixed to ErrInvalidEncodedString via this '%s: %w' wrapper.","triggerScenarios":"Calling BufDecodeStringSQL (or DecodeStringSQL) with a string missing the surrounding quotes, an empty string, or an already-decoded value that no longer carries quotes.","commonSituations":"Passing values extracted from bind variables or configs that were already unquoted; double-decoding an unquoted literal; truncation that stripped the closing quote.","solutions":["Ensure the input is a complete quoted literal like 'abc' before decoding","If already decoded, skip DecodeStringSQL and use the value as-is","Check upstream code for an unintended earlier unquote step"],"exampleFix":"// before\nsqltypes.DecodeStringSQL(\"abc\")\n// after\nsqltypes.DecodeStringSQL(\"'abc'\")","handlingStrategy":"validation","validationCode":"func isQuotedLiteral(s string) bool {\n  return len(s) >= 2 && s[0] == '\\'' && s[len(s)-1] == '\\''\n}","typeGuard":null,"tryCatchPattern":"if !isQuotedLiteral(val) {\n  // use val as-is, already decoded\n} else if err := sqltypes.BufDecodeStringSQL(&sb, val); err != nil {\n  return vterrors.Wrapf(err, \"decode %q\", val)\n}","preventionTips":["Decode exactly once; track whether a value is still encoded","Never truncate quoted literals","Quote with a helper instead of manual concatenation"],"tags":["sqltypes","string-decoding","quoting"],"backgroundTag":"invalid-encoded-string","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}