From f9b2fbb3b196da7ffbe6432be535ec0926202d33 Mon Sep 17 00:00:00 2001 From: xucian <5688727+xucian@users.noreply.github.com> Date: Fri, 23 Oct 2026 23:40:30 +0300 Subject: [PATCH] hints: Fix Unicode quotes not being removed from paths and URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The post-processors index the text by byte, so when looking at the character before a position they decoded only the last byte of multi-byte quotes such as ‘’ and “” and never matched them. URLs kept the closing quote and paths kept both quotes. When the closing quote was just outside the match, the start was also advanced by a single byte, splitting the opening quote and producing invalid UTF-8, for example, for the file name in wget's "Saving to: ‘index.html’". This worked before the hints kitten was ported to Go. --- docs/changelog.rst | 3 +++ kittens/hints/marks.go | 20 ++++++++++++++------ kittens/hints/marks_test.go | 4 ++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b64f2557f..204e36f2b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -450,6 +450,9 @@ Detailed list of changes or too thick when zoomed out. At the configured :opt:`font_size` nothing changes (:iss:`10362`) +- hints kitten: Fix Unicode quotes not being removed from around paths and + URLs, such as file names in the output of wget + 0.49.2 [2026-10-01] diff --git a/kittens/hints/marks.go b/kittens/hints/marks.go index 737be04b9..17ed5731c 100644 --- a/kittens/hints/marks.go +++ b/kittens/hints/marks.go @@ -138,17 +138,25 @@ func char_at(s string, i int) string { return string(ans) } +func char_before(s string, i int) string { + ans, _ := utf8.DecodeLastRuneInString(s[:i]) + if ans == utf8.RuneError { + return "" + } + return string(ans) +} + func matching_remover(openers ...string) PostProcessorFunc { return func(text string, s, e int) (int, int) { if s < e && e <= len(text) { before := char_at(text, s) if slices.Index(openers, before) > -1 { q := closing_bracket_for(before) - if e > 0 && char_at(text, e-1) == q { - s++ - e-- + if e > 0 && char_before(text, e) == q { + s += len(before) + e -= len(q) } else if char_at(text, e) == q { - s++ + s += len(before) } } } @@ -179,8 +187,8 @@ var PostProcessorMap = sync.OnceValue(func() map[string]PostProcessorFunc { e-- } // truncate url at closing bracket/quote - if s > 0 && e <= len(text) && closing_bracket_for(char_at(text, s-1)) != "" { - q := closing_bracket_for(char_at(text, s-1)) + if s > 0 && e <= len(text) && closing_bracket_for(char_before(text, s)) != "" { + q := closing_bracket_for(char_before(text, s)) idx := strings.Index(text[s:], q) if idx > 0 { e = s + idx diff --git a/kittens/hints/marks_test.go b/kittens/hints/marks_test.go index 0639140ee..76c91dde4 100644 --- a/kittens/hints/marks_test.go +++ b/kittens/hints/marks_test.go @@ -71,6 +71,8 @@ func TestHintMarking(t *testing.T) { r("http://example.com.", "http://example.com") r("http://example.com!", "http://example.com") r("http://example.com?", "http://example.com") + r("“"+u+"”", u) + r("‘"+u+"’", u) opts.Type = "linenum" m := func(text, path string, line int) { @@ -98,6 +100,8 @@ func TestHintMarking(t *testing.T) { r("file.epub.", "file.epub") r("(file.epub)", "file.epub") r("some/path", "some/path") + r("“some/path”", "some/path") + r("Saving to: ‘index.html’", "index.html") // long lines without spaces must not cause quadratic backtracking long_line := strings.Repeat("1,", 20000) r(long_line)