diff --git a/src/cursor.ts b/src/cursor.ts index 54ddefc..97f77dd 100644 --- a/src/cursor.ts +++ b/src/cursor.ts @@ -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++ } } diff --git a/test/test-cursor.ts b/test/test-cursor.ts index abce812..ee1ffe4 100644 --- a/test/test-cursor.ts +++ b/test/test-cursor.ts @@ -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", () => {