Merge branch 'fix-shlex-drops-escaped-replacement-char' of https://github.com/devangpratap/kitty
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

This commit is contained in:
Kovid Goyal 2026-09-21 22:20:23 +05:30
commit 31c16b37b3
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 1 deletions

View file

@ -71,7 +71,8 @@ func (self *Lexer) write_escaped_ch() bool {
ch, count := utf8.DecodeRuneInString(self.src[self.src_pos:])
if count > 0 {
self.src_pos += count
if ch != utf8.RuneError {
// Invalid UTF-8 always decodes as (RuneError, 1), so a larger size means a real U+FFFD.
if ch != utf8.RuneError || count > 1 {
self.buf.WriteRune(ch)
}
return true

View file

@ -81,6 +81,11 @@ func TestSplit(t *testing.T) {
``: nil,
` `: nil,
" \tabc\n\t\r ": {{2, "abc"}},
"a\\\xffb": {{0, "ab"}}, // an escaped invalid byte is still dropped
// An escaped U+FFFD is a real character, not a decoding failure, so it
// survives the escape the way it does unescaped or single quoted.
"a\\<5C>b": {{0, "a<>b"}},
"\"a\\<5C>b\"": {{0, "a<>b"}},
} {
if diff := cmp.Diff(expected, s(q)); diff != "" {
t.Fatalf("Failed for string: %#v\n%s", q, diff)