FIX: word boundary regex (\b) not working in Unicode languages. (#9163)

This commit is contained in:
Vinoth Kannan
2020-03-25 18:39:19 +05:30
committed by GitHub
parent 49395ec577
commit 572bb5988f
13 changed files with 175 additions and 161 deletions

View File

@ -0,0 +1,48 @@
import highlightSearch, { CLASS_NAME } from "discourse/lib/highlight-search";
import { fixture } from "helpers/qunit-helpers";
QUnit.module("lib:highlight-search");
QUnit.test("highlighting text", assert => {
fixture().html(
`
<p>This is some text to highlight</p>
`
);
highlightSearch(fixture(), "some text");
const terms = [];
fixture(`.${CLASS_NAME}`).each((_, elem) => {
terms.push(elem.textContent);
});
assert.equal(
terms.join(" "),
"some text",
"it should highlight the terms correctly"
);
});
QUnit.test("highlighting unicode text", assert => {
fixture().html(
`
<p>This is some தமிழ் and русский text to highlight</p>
`
);
highlightSearch(fixture(), "தமிழ் русский");
const terms = [];
fixture(`.${CLASS_NAME}`).each((_, elem) => {
terms.push(elem.textContent);
});
assert.equal(
terms.join(" "),
"தமிழ் русский",
"it should highlight the terms correctly"
);
});