Skip to content

Commit

Permalink
Make SearchCursor ignore matches that match only part of a normalized…
Browse files Browse the repository at this point in the history
… character

FIX: Fix an issue in `SearchCursor` where character normalization could produce nonsensical matches.

Closes codemirror/dev#1219
  • Loading branch information
marijnh committed Aug 4, 2023
1 parent ce45216 commit 7748622
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/cursor.ts
Expand Up @@ -77,11 +77,13 @@ export class SearchCursor implements Iterator<{from: number, to: number}>{
for (let i = 0, pos = start;; i++) {
let code = norm.charCodeAt(i)
let match = this.match(code, pos)
if (match) {
this.value = match
return this
}
if (i == norm.length - 1) break
if (i == norm.length - 1) {
if (match) {
this.value = match
return this
}
break
}
if (pos == start && i < str.length && str.charCodeAt(i) == code) pos++
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/test-cursor.ts
Expand Up @@ -60,6 +60,10 @@ describe("SearchCursor", () => {
while (!cursor.nextOverlapping().done) matches.push([cursor.value.from, cursor.value.to])
ist(JSON.stringify(matches), "[[0,4],[2,6],[4,8]]")
})

it("will not match partial normalized content", () => {
testMatches(new SearchCursor(Text.of(["´"]), " "), [])
})
})

describe("RegExpCursor", () => {
Expand Down

0 comments on commit 7748622

Please sign in to comment.