Skip to content

Commit d7116ab

Browse files
committed
Fix incorrect regex matching
Fix linting
1 parent 4c4158e commit d7116ab

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/util/TextSelectionManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export function createTextFragmentUrlParam(selection, pageLayer) {
269269
const textEndRe = RegExp.escape(endWord);
270270

271271
// 's' regex modifier ensures the `.` also captures newline characters
272-
const phraseMatchRe = new RegExp(String.raw`(?=(${textStartRe}).*?(?:(${textEndRe})))`, "gis");
272+
const phraseMatchRe = new RegExp(String.raw`(?<=(${textStartRe}).*?)(${textEndRe})`, "gis");
273273
// Duplicated spaces in pageLayer.textContent for some reason
274274
const wholePageText = pageLayer.textContent.replaceAll(" ", " ");
275275
const foundMatches = wholePageText.matchAll(phraseMatchRe).toArray();

tests/jest/util/TextSelectionManager.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe("TextFragment tests", () => {
267267
window.getSelection().direction = 'backward';
268268
const backwardTest = createTextFragmentUrlParam(selection, document.querySelector('.BRtextLayer'));
269269

270-
expect(forwardTest).toMatch("text=way,false");
270+
expect(forwardTest).toMatch("text=way%20can%20false,-judgment%20be%20-");
271271
expect(backwardTest).toMatch(forwardTest);
272272
});
273273

0 commit comments

Comments
 (0)