lib/irc: escape/unescape everything in tags

Without the greedy flag on the regexp, String.replace will just
replace the first match.

While at it, also make sure to convert to a string when formatting
tag values. This allows tag values to be e.g. numbers.
This commit is contained in:
Simon Ser 2021-03-09 17:40:57 +01:00
parent 2d4409e7aa
commit 8ab10cf2a5

View file

@ -43,11 +43,11 @@ const tagEscapeMap = {
const tagUnescapeMap = Object.fromEntries(Object.entries(tagEscapeMap).map(([from, to]) => [to, from]));
function escapeTag(s) {
return s.replace(/[; \\\r\n]/, (ch) => tagEscapeMap[ch]);
return String(s).replace(/[; \\\r\n]/g, (ch) => tagEscapeMap[ch]);
}
function unescapeTag(s) {
return s.replace(/\\[:s\\rn]/, (seq) => tagUnescapeMap[seq]);
return s.replace(/\\[:s\\rn]/g, (seq) => tagUnescapeMap[seq]);
}
export function parseTags(s) {