Skip to content

Commit b54df53

Browse files
authored
Merge pull request #97 from graulund/graulund/escape-tags-values
Escape IRCv3 tags values
2 parents a3cebe5 + a7d6d52 commit b54df53

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/irclineparser.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ module.exports = parseIrcLine;
99
*/
1010
var parse_regex = /^(?:@([^ ]+) )?(?::((?:(?:([^\s!@]+)(?:!([^\s@]+))?)@)?(\S+)) )?((?:[a-zA-Z]+)|(?:[0-9]{3}))(?: ([^:].*?))?(?: :(.*))?$/i;
1111

12+
var escape_tags_map = {
13+
'\\\\': '\\',
14+
'\\:': ';',
15+
'\\s': ' ',
16+
'\\n': '\n',
17+
'\\r': '\r'
18+
};
19+
1220
function parseIrcLine(line) {
1321
var msg;
1422
var tags = Object.create(null);
@@ -26,9 +34,18 @@ function parseIrcLine(line) {
2634
if (msg[1]) {
2735
msg[1].split(';').forEach(function(tag) {
2836
var parts = tag.split('=');
29-
tags[parts[0].toLowerCase()] = typeof parts[1] === 'undefined' ?
30-
true :
31-
parts[1];
37+
var key = parts[0].toLowerCase();
38+
var value = parts[1];
39+
if (key) {
40+
if (typeof value === 'string') {
41+
value = value.replace(/\\\\|\\:|\\s|\\n|\\r/gi, function(matched) {
42+
return escape_tags_map[matched] || '';
43+
});
44+
} else {
45+
value = true;
46+
}
47+
tags[key] = value;
48+
}
3249
});
3350
}
3451

0 commit comments

Comments
 (0)