diff --git a/docs/changelog.rst b/docs/changelog.rst index ad1fceb52..327fcba03 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -454,7 +454,7 @@ Detailed list of changes changing font settings (:iss:`10729`) - hints kitten: Fix Unicode quotes not being removed from around paths and - URLs, such as file names in the output of wget + URLs, such as file names in the output of wget (:pull:`10730`) diff --git a/kittens/hints/marks.go b/kittens/hints/marks.go index 17ed5731c..9450ef018 100644 --- a/kittens/hints/marks.go +++ b/kittens/hints/marks.go @@ -152,7 +152,7 @@ func matching_remover(openers ...string) PostProcessorFunc { before := char_at(text, s) if slices.Index(openers, before) > -1 { q := closing_bracket_for(before) - if e > 0 && char_before(text, e) == q { + if s+len(before) <= e-len(q) && char_before(text, e) == q { s += len(before) e -= len(q) } else if char_at(text, e) == q { @@ -183,15 +183,16 @@ var PostProcessorMap = sync.OnceValue(func() map[string]PostProcessorFunc { e -= len(url) - idx } } - for e > 1 && is_punctuation(char_at(text, e-1)) { // remove trailing punctuation + for e > 1 && is_punctuation(char_before(text, e)) { // remove trailing punctuation e-- } // truncate url at closing bracket/quote - 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 + if s > 0 && e <= len(text) { + if q := closing_bracket_for(char_before(text, s)); q != "" { + idx := strings.Index(text[s:], q) + if idx > 0 { + e = s + idx + } } } // reStructuredText URLs diff --git a/kittens/hints/marks_test.go b/kittens/hints/marks_test.go index 76c91dde4..0418c06f8 100644 --- a/kittens/hints/marks_test.go +++ b/kittens/hints/marks_test.go @@ -102,6 +102,14 @@ func TestHintMarking(t *testing.T) { r("some/path", "some/path") r("“some/path”", "some/path") r("Saving to: ‘index.html’", "index.html") + // a match consisting of only a quote must not result in start > end + for _, text := range []string{`"`, `'`, `""`, "“”", "“"} { + for _, name := range []string{"quotes", "brackets"} { + if s, e := PostProcessorMap()[name](text, 0, len(text)); s > e { + t.Fatalf("%s post processor returned start (%d) > end (%d) for %#v", name, s, e, text) + } + } + } // long lines without spaces must not cause quadratic backtracking long_line := strings.Repeat("1,", 20000) r(long_line)