Merge PR #10730: hints: Fix Unicode quotes not being removed from paths and URLs

This commit is contained in:
Kovid Goyal 2026-10-24 06:35:13 +05:30
commit 92e9e6a038
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 21 additions and 6 deletions

View file

@ -453,6 +453,9 @@ Detailed list of changes
- Fix a use-after-free that could cause a crash when reloading the config after
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
0.49.2 [2026-10-01]

View file

@ -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

View file

@ -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)