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:
@@ -43,11 +43,11 @@ const tagEscapeMap = {
|
|||||||
const tagUnescapeMap = Object.fromEntries(Object.entries(tagEscapeMap).map(([from, to]) => [to, from]));
|
const tagUnescapeMap = Object.fromEntries(Object.entries(tagEscapeMap).map(([from, to]) => [to, from]));
|
||||||
|
|
||||||
function escapeTag(s) {
|
function escapeTag(s) {
|
||||||
return s.replace(/[; \\\r\n]/, (ch) => tagEscapeMap[ch]);
|
return String(s).replace(/[; \\\r\n]/g, (ch) => tagEscapeMap[ch]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unescapeTag(s) {
|
function unescapeTag(s) {
|
||||||
return s.replace(/\\[:s\\rn]/, (seq) => tagUnescapeMap[seq]);
|
return s.replace(/\\[:s\\rn]/g, (seq) => tagUnescapeMap[seq]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseTags(s) {
|
export function parseTags(s) {
|
||||||
|
|||||||
Reference in New Issue
Block a user