Skip to content

Commit 569440e

Browse files
committed
fixes multiple findings in overlapping range
1 parent 395bc05 commit 569440e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/analyseText.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function analyseText(text, channelPrefixes = ['#']) {
6060
end: end,
6161
link: 'http://' + text.slice(start, end)
6262
});
63+
position = end;
6364
}
6465
} else if (channelPrefixes.indexOf(text[position]) !== -1 &&
6566
(position === 0 || /[^0-9a-z]/i.test(text[position - 1]))) {
@@ -75,6 +76,7 @@ function analyseText(text, channelPrefixes = ['#']) {
7576
end: end,
7677
channel: text.slice(start, end)
7778
});
79+
position = end;
7880
}
7981
}
8082
position += 1;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ircmessageparser",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "parses irc messages and extracts styling informations, urls and channels",
55
"main": "index.js",
66
"directories": {

test/analyseText.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,29 @@ describe('analyseText', () => {
223223
expect(actual).to.deep.equal(expected);
224224
});
225225

226+
it('should handle multiple channelPrefix correctly', () => {
227+
const input = '##test';
228+
const expected = [{
229+
channel: '##test',
230+
start: 0,
231+
end: 6
232+
}];
233+
234+
const actual = analyseText(input);
235+
236+
expect(actual).to.deep.equal(expected);
237+
});
238+
239+
it('should handle multiple www. correctly', () => {
240+
const input = 'www.www.test.com';
241+
const expected = [{
242+
link: 'http://www.www.test.com',
243+
start: 0,
244+
end: 16
245+
}];
246+
247+
const actual = analyseText(input);
248+
249+
expect(actual).to.deep.equal(expected);
250+
});
226251
});

0 commit comments

Comments
 (0)