Skip to content

Commit 799ae5b

Browse files
committed
Fix RegExp modifier and encode unique text matches
1 parent a523b45 commit 799ae5b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/util/TextSelectionManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,13 @@ export function createParam(selection, pageLayer) {
278278

279279
const escapedStart = RegExp.escape(textStart);
280280
const escapedEnd = RegExp.escape(textEnd);
281-
const testRegExp = new RegExp(String.raw`(?=(${escapedStart}).*?(?:(${escapedEnd})))`, "gi");
281+
282+
// added 's' regex modifier to ensure that the matchAll actually captures instances where the escaped start / end words have whitespace
283+
const testRegExp = new RegExp(String.raw`(?=(${escapedStart}).*?(?:(${escapedEnd})))`, "gis");
282284

283285
const foundMatches = wholePageText.matchAll(testRegExp).toArray();
284286
if (foundMatches.length == 1) {
285-
return `text=${textStart},${textEnd}`;
287+
return `text=${encodeURIComponent(textStart)},${encodeURIComponent(textEnd)}`;
286288
}
287289
const preStartRange = document.createRange();
288290
const postEndRange = document.createRange();

0 commit comments

Comments
 (0)