From 8ab10cf2a5fd56a1e5173a9b929d3bf17d8e5f45 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 9 Mar 2021 17:40:57 +0100 Subject: [PATCH] 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. --- lib/irc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/irc.js b/lib/irc.js index 7c730db..16fbee6 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -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) {