mirror of
https://github.com/thelounge/thelounge
synced 2024-11-29 07:20:25 +00:00
Fix duplicate user names not being found
This commit is contained in:
parent
a7bd40a5b1
commit
d770028da6
2 changed files with 29 additions and 2 deletions
|
@ -2,15 +2,17 @@
|
||||||
|
|
||||||
function findNames(text, users) {
|
function findNames(text, users) {
|
||||||
const result = [];
|
const result = [];
|
||||||
let index = 0;
|
let index = -1;
|
||||||
|
|
||||||
users.forEach((nick) => {
|
users.forEach((nick) => {
|
||||||
index = text.indexOf(nick, index);
|
index = text.indexOf(nick, ++index);
|
||||||
result.push({
|
result.push({
|
||||||
start: index,
|
start: index,
|
||||||
end: index + nick.length,
|
end: index + nick.length,
|
||||||
nick: nick,
|
nick: nick,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,4 +23,29 @@ describe("findNames", () => {
|
||||||
|
|
||||||
expect(actual).to.deep.equal(expected);
|
expect(actual).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should find same nick multiple times", () => {
|
||||||
|
const input = "xPaw xPaw xPaw";
|
||||||
|
const expected = [
|
||||||
|
{
|
||||||
|
start: 0,
|
||||||
|
end: 4,
|
||||||
|
nick: "xPaw",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 5,
|
||||||
|
end: 9,
|
||||||
|
nick: "xPaw",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: 10,
|
||||||
|
end: 14,
|
||||||
|
nick: "xPaw",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const nicks = ["xPaw", "xPaw", "xPaw"];
|
||||||
|
const actual = findNames(input, nicks);
|
||||||
|
|
||||||
|
expect(actual).to.deep.equal(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue