{"record":{"id":"6a7167e1e2039f93","repo":"gitbutlerapp/gitbutler","slug":"unterminated-escape-sequence-in-quoted-message","errorCode":null,"errorMessage":"unterminated escape sequence in quoted message","messagePattern":"unterminated escape sequence in quoted message","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/integrate_branch_upstream/parsing.rs","lineNumber":215,"sourceCode":"            escaped = false;\n            continue;\n        }\n\n        match ch {\n            '\\\\' => escaped = true,\n            '\"' => {\n                let trailing = input[index + ch.len_utf8()..].trim();\n                if trailing.is_empty() {\n                    return Ok(output);\n                }\n                bail!(\"unexpected trailing characters after quoted message\");\n            }\n            other => output.push(other),\n        }\n    }\n\n    if escaped {\n        bail!(\"unterminated escape sequence in quoted message\");\n    }\n    bail!(\"unterminated quoted message\")\n}\n\nfn quote_message(message: &str) -> String {\n    let mut out = String::from(\"\\\"\");\n    for ch in message.chars() {\n        match ch {\n            '\\\\' => out.push_str(\"\\\\\\\\\"),\n            '\"' => out.push_str(\"\\\\\\\"\"),\n            '\\n' => out.push_str(\"\\\\n\"),\n            '\\r' => out.push_str(\"\\\\r\"),\n            '\\t' => out.push_str(\"\\\\t\"),\n            other => out.push(other),\n        }\n    }\n    out.push('\"');\n    out","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/integrate_branch_upstream/parsing.rs#L197-L233","documentation":"When parsing a quoted message string (e.g. from a rebase/plan editor input), a backslash escape was started but the string ended before the escaped character appeared. The parser tracks an `escaped` flag while consuming characters and bails once input is exhausted mid-escape, because the message is malformed and its intent cannot be reconstructed.","triggerScenarios":"Calling parse_message_clause (via integrate-branch-upstream parsing) on an editor buffer whose quoted message ends with a trailing backslash, e.g. `\"commit message\\` with no character after the backslash.","commonSituations":"Hand-edited rebase templates or programmatically generated plan files where quoting/escaping logic dropped the final escaped character, or shell/JSON tooling stripped the character following a backslash.","solutions":["Add the character intended to follow the backslash (or remove the trailing backslash) so the quoted message ends with a proper closing quote","If the backslash is literal content, escape it as `\\\\` so the parser consumes a complete escape sequence","Regenerate the message via the library's own quote_message() instead of hand-building quoted strings"],"exampleFix":"// before\nmessage = \"fix: handle path\\\";\n// after\nmessage = \"fix: handle path\\\\\";","handlingStrategy":"validation","validationCode":"fn is_balanced_quoted(s: &str) -> bool {\n    let bytes = s.as_bytes();\n    if bytes.len() < 2 || !bytes[0] == b'\"' { return false; }\n    let mut i = 1;\n    while i < bytes.len() {\n        match bytes[i] {\n            b'\\\\' if i + 1 >= bytes.len() - 1 => return false, // trailing escape\n            b'\\\\' => i += 2,\n            b'\"' => return i == bytes.len() - 1,\n            _ => i += 1,\n        }\n    }\n    false\n}","typeGuard":null,"tryCatchPattern":"match parse_message_clause(input) {\n    Err(e) if e.to_string().contains(\"unterminated escape\") => fix_trailing_backslash(input),\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Always generate quoted messages with quote_message() instead of string concatenation","Strip or double trailing backslashes before writing editor input","Round-trip test generated plan files through the parser"],"tags":["parsing","git","escape-sequence"],"backgroundTag":"invalid-argument-format","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}