mirror of
https://github.com/thelounge/thelounge
synced 2024-11-10 22:54:15 +00:00
Merge pull request #3073 from Jay2k1/patch-2
extend custom highlight regex
This commit is contained in:
commit
c574234b99
2 changed files with 78 additions and 1 deletions
|
@ -402,7 +402,7 @@ Client.prototype.compileCustomHighlights = function() {
|
|||
return;
|
||||
}
|
||||
|
||||
client.highlightRegex = new RegExp(`(?:^| |\t)(?:${highlightsTokens.join("|")})(?:\t| |$)`, "i");
|
||||
client.highlightRegex = new RegExp(`(?:^|[ .,+!?|/:<>(){}'"@&~-])(?:${highlightsTokens.join("|")})(?:$|[ .,+!?|/:<>(){}'"-])`, "i");
|
||||
};
|
||||
|
||||
Client.prototype.more = function(data) {
|
||||
|
|
77
test/tests/customhighlights.js
Normal file
77
test/tests/customhighlights.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
"use strict";
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const Client = require("../../src/client");
|
||||
|
||||
const client = new Client({}, "test", {clientSettings: {highlights: "foo, @all, sp ace , 고"}});
|
||||
|
||||
describe("Custom highlights", function() {
|
||||
it("should NOT highlight", function() {
|
||||
const teststrings = [
|
||||
"and foos stuff",
|
||||
"test foobar",
|
||||
"testfoo bar",
|
||||
"fooö",
|
||||
"wtf@all",
|
||||
"foo고",
|
||||
"test고",
|
||||
"space",
|
||||
"sp:ace",
|
||||
];
|
||||
|
||||
for (const teststring of teststrings) {
|
||||
expect(teststring).to.not.match(client.highlightRegex);
|
||||
}
|
||||
});
|
||||
|
||||
it("should highlight", function() {
|
||||
const teststrings = [
|
||||
"Hey foo hello",
|
||||
"hey Foo: hi",
|
||||
"hey Foo, hi",
|
||||
"<foo> testing",
|
||||
"foo",
|
||||
"hey @all test",
|
||||
"testing foo's stuff",
|
||||
"\"foo\"",
|
||||
"\"@all\"",
|
||||
"foo!",
|
||||
"www.foo.bar",
|
||||
"www.bar.foo/page",
|
||||
"고",
|
||||
"test 고",
|
||||
"고!",
|
||||
"www.고.com",
|
||||
"hey @Foo",
|
||||
"hey ~Foo",
|
||||
"hey +Foo",
|
||||
"hello &foo",
|
||||
"@all",
|
||||
"@all wtf",
|
||||
"wtf @all",
|
||||
"@@all",
|
||||
"@고",
|
||||
"f00 sp ace: bar",
|
||||
];
|
||||
|
||||
for (const teststring of teststrings) {
|
||||
expect(teststring).to.match(client.highlightRegex);
|
||||
}
|
||||
});
|
||||
|
||||
it("should trim custom highlights in the compiled regex", function() {
|
||||
expect(client.highlightRegex).to.match(/\(\?:foo\|@all\|sp ace\|고\)/);
|
||||
});
|
||||
|
||||
it("should NOT compile a regex", function() {
|
||||
// test updating the regex and invalid custom hl inputs
|
||||
client.config.clientSettings.highlights = ",,";
|
||||
client.compileCustomHighlights();
|
||||
expect(client.highlightRegex).to.be.null;
|
||||
|
||||
client.config.clientSettings.highlights = " ";
|
||||
client.compileCustomHighlights();
|
||||
expect(client.highlightRegex).to.be.null;
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue