lib/irc: accept tags without value

This commit is contained in:
Simon Ser 2021-03-09 17:31:12 +01:00
parent 4257463b46
commit 2d4409e7aa

View file

@ -52,18 +52,18 @@ function unescapeTag(s) {
export function parseTags(s) {
var tags = {};
s.split(";").forEach(function(s) {
s.split(";").forEach((s) => {
if (!s) {
return;
}
var parts = s.split("=", 2);
if (parts.length != 2) {
throw new Error("expected an equal sign in tag");
}
var k = parts[0];
var v = unescapeTag(parts[1]);
if (v.endsWith("\\")) {
v = v.slice(0, v.length - 1)
var v = null;
if (parts.length == 2) {
v = unescapeTag(parts[1]);
if (v.endsWith("\\")) {
v = v.slice(0, v.length - 1)
}
}
tags[k] = v;
});
@ -73,6 +73,10 @@ export function parseTags(s) {
export function formatTags(tags) {
var l = [];
for (var k in tags) {
if (tags[k] === undefined || tags[k] === null) {
l.push(k);
continue;
}
var v = escapeTag(tags[k]);
l.push(k + "=" + v);
}