hints: Cleanup previous PR
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

- Guard against the quotes post processor producing start > end for a match
  consisting of just a single ASCII quote
- Use char_before() in the URL trailing punctuation loop and avoid computing
  the closing bracket twice
- Add PR reference to changelog entry
This commit is contained in:
Kovid Goyal 2026-10-24 06:36:26 +05:30
parent 92e9e6a038
commit 81535d9b33
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 17 additions and 8 deletions

View file

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

View file

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

View file

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