{"record":{"id":"88bd40ecece7121a","repo":"databendlabs/databend","slug":"expected-to-have-quotes-in-string-literal","errorCode":null,"errorMessage":"Expected to have quotes in string literal.","messagePattern":"Expected to have quotes in string literal\\.","errorType":"validation","errorClass":"InvalidData","httpStatus":null,"severity":"error","filePath":"src/common/io/src/cursor_ext/cursor_read_string_ext.rs","lineNumber":198,"sourceCode":"        }\n        Err(std::io::Error::new(\n            ErrorKind::InvalidData,\n            format!(\n                \"Expected to have terminated string literal after quota \\', while consumed buf: {:?}\",\n                buf\n            ),\n        ))\n    }\n}\n\n// Check that the pre-calculated position is correct.\nfn check_pos(curr_pos: usize, positions: &mut VecDeque<usize>) -> Result<()> {\n    if let Some(pos) = positions.pop_front()\n        && curr_pos == pos\n    {\n        return Ok(());\n    }\n    Err(std::io::Error::new(\n        ErrorKind::InvalidData,\n        \"Expected to have quotes in string literal.\".to_string(),\n    ))\n}\n\nfn unescape(c: u8) -> u8 {\n    match c {\n        b'a' => b'\\x07', // \\a in c\n        b'b' => b'\\x08', // \\b in c\n        b'v' => b'\\x0B', // \\v in c\n        b'f' => b'\\x0C', // \\f in c\n        b'e' => b'\\x1B', // \\e in c\n        b'n' => b'\\n',\n        b'r' => b'\\r',\n        b't' => b'\\t',\n        b'0' => b'\\0',\n        _ => c,\n    }","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/io/src/cursor_ext/cursor_read_string_ext.rs#L180-L216","documentation":"Raised by the `check_pos` helper used by `fast_read_quoted_text`. The fast path pre-records the byte positions of quote/escape characters and verifies them while rescanning; if the cursor's current position does not match any recorded quote position, the literal is assumed malformed and this InvalidData error is returned.","triggerScenarios":"Calling `fast_read_quoted_text` on input whose escape/quote structure is inconsistent — e.g. the scanner lands on a position that was not registered as a quote, which happens with malformed escapes, unbalanced quotes, or bytes that altered the scan trajectory (multi-byte/invalid UTF-8 sequences in the middle of the literal).","commonSituations":"String literals containing invalid UTF-8, mixed quote styles, or hand-edited SQL where an escape was removed but its target position stayed — any case where the fast scanner's recorded quote positions no longer line up with the actual input.","solutions":["Fall back to the non-fast `read_quoted_text` (via `read_string_text`) which is more tolerant and gives better diagnostics.","Verify the literal is valid UTF-8 and uses a single consistent quote character.","Check for unbalanced or unescaped quotes/escapes in the offending literal.","If parsing third-party text, pre-normalize it (re-escape quotes) before calling the fast parser."],"exampleFix":"// before: fast path on suspicious input\nlet s = \"'weird\\\\\\\"literal\".as_bytes().fast_read_quoted_text(&mut buf)?;\n// after: use the robust reader for untrusted input\nlet s = \"'weird\\\\\\\"literal'\".as_bytes().read_quoted_text(&mut buf)?;","handlingStrategy":"fallback","validationCode":"fn valid_utf8_literal(input: &[u8]) -> bool {\n    std::str::from_utf8(input).is_ok()\n}","typeGuard":"fn usable_by_fast_path(input: &[u8]) -> bool {\n    std::str::from_utf8(input).map(|s| {\n        s.starts_with('\\'') && s.ends_with('\\'')\n    }).unwrap_or(false)\n}","tryCatchPattern":"let result = match fast_read_quoted_text(&mut buf) {\n    Ok(s) => Ok(s),\n    Err(_) => input.as_bytes().read_quoted_text(&mut buf), // tolerant fallback\n};","preventionTips":["Validate UTF-8 before using the fast path.","Fall back to read_quoted_text whenever the fast scanner fails.","Keep literal content free of control/invalid bytes."],"tags":["parsing","string-literal","fast-path"],"backgroundTag":"unterminated-string-literal","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}