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)