GoogleChromeLabs / text-fragments-polyfill

Apache License 2.0
116 stars 27 forks source link

Fix range matching when punctuation is involved #71

Closed guillaumejenkins closed 3 years ago

guillaumejenkins commented 3 years ago

The current implementation of range matching ignores punctuation between the prefix and the text start. Not only is this not up to specs, it can cause false positives in range matches.

The problem is that when looking for the text start, the algorithm advances to the first non-boundary position after matching the prefix. According to the specs it should instead advance to the first non-whitespace position.

Because the |advanceRangeStartToNonBoundary| function was only used for range matching, it was repurposed for this fix rather than creating a new function.

Fixes #70