Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/unit/pdf_find_controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1213,4 +1213,54 @@ describe("pdf_find_controller", function () {
});
});
});

it("should not match punctuation with spaces when searching for exact punctuation", async function () {
// Test case for issue #20225: searching for "...." should not match ". ..." or ".. .."
const mockMatcher = function (query, pageContent) {
// Simulate page content with various dot patterns
const testContent = "This has four dots.... and this has dot space three dots. ... and this has two dots space two dots.. ..";

// Call the original match method to test the current behavior
return PDFFindController.prototype.match.call(this, query, testContent, 0);
};

const { eventBus, pdfFindController } = await initPdfFindController(
null,
false,
mockMatcher
);

// Test searching for exactly four dots - should only match exact sequence
await testSearch({
eventBus,
pdfFindController,
state: { query: "...." },
selectedMatch: { pageIndex: 0, matchIndex: 0 },
matchesPerPage: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // Should match only 1 exact occurrence
});
});

it("should not match text with spaces when searching for text without spaces", async function () {
// Test case for issue: searching for "hello.world" should not match "hello. world"
const mockMatcher = function (query, pageContent) {
const testContent = "hello. world and hello.world are different";

// Call the original match method to test the current behavior
return PDFFindController.prototype.match.call(this, query, testContent, 0);
};

const { eventBus, pdfFindController } = await initPdfFindController(
null,
false,
mockMatcher
);

await testSearch({
eventBus,
pdfFindController,
state: { query: "hello.world" },
selectedMatch: { pageIndex: 0, matchIndex: 0 },
matchesPerPage: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // Should match only 1 exact occurrence
});
});
});
6 changes: 3 additions & 3 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ class PDFFindController {

if (p1) {
// Escape characters like *+?... to not interfere with regexp syntax.
return `[ ]*\\${p1}[ ]*`;
return `\\${p1}`;
}
if (p2) {
// Allow whitespaces around punctuation signs.
return `[ ]*${p2}[ ]*`;
// Match punctuation signs exactly without allowing arbitrary whitespaces.
return p2;
}
if (p3) {
// Replace spaces by \s+ to be sure to match any spaces.
Expand Down