result.append(*it);
}
escaped = false;
- } else if (it->unicode() == '\\') {
+ }
+ else if (it->unicode() == '\\') {
escaped = true;
- } else {
+ }
+ else {
result.append(*it);
}
}
if (key.clientTag) {
rawKey.remove(0, 1);
}
- QList<QString> splitByVendorAndKey = rawKey.split('/');
- if (!splitByVendorAndKey.isEmpty()) key.key = splitByVendorAndKey.takeLast();
- if (!splitByVendorAndKey.isEmpty()) key.vendor = splitByVendorAndKey.takeLast();
+
+ int splitIndex = rawKey.lastIndexOf('/');
+ if (splitIndex > 0 && splitIndex + 1 < rawKey.length()) {
+ key.key = rawKey.mid(splitIndex + 1);
+ key.vendor = rawKey.left(splitIndex);
+ }
+ else {
+ key.key = rawKey;
+ }
tags[key] = parseTagValue(rawValue);
}
return tags;
}
}
-void IrcDecoder::parseMessage(const std::function<QString(const QByteArray&)>& decode, const QByteArray& rawMsg, QHash<IrcTagKey, QString>& tags, QString& prefix, QString& command, QList<QByteArray>& parameters)
+void IrcDecoder::parseMessage(const std::function<QString(const QByteArray&)>& decode,
+ const QByteArray& rawMsg,
+ QHash<IrcTagKey, QString>& tags,
+ QString& prefix,
+ QString& command,
+ QList<QByteArray>& parameters)
{
int start = 0;
skipEmptyParts(rawMsg, start);
QByteArray param = parseParameter(rawMsg, start);
skipEmptyParts(rawMsg, start);
params.append(param);
-
}
parameters = params;
}
{IrcTagKey("rt"), "ql7"}},
"",
"foo"));
+
+ EXPECT_EQ(parse("@a=b foo"),
+ IrcMessage(
+ {{IrcTagKey("a"), "b"}},
+ "",
+ "foo"));
+
+ EXPECT_EQ(parse("@example.com/a=b foo"),
+ IrcMessage(
+ {{IrcTagKey("example.com", "a"), "b"}},
+ "",
+ "foo"));
+
+ EXPECT_EQ(parse("@example.com/subfolder/to/a=b foo"),
+ IrcMessage(
+ {{IrcTagKey("example.com/subfolder/to", "a"), "b"}},
+ "",
+ "foo"));
+
+ EXPECT_EQ(parse("@v\\/e\\/n\\/d\\/o\\/r/tag=b foo"),
+ IrcMessage(
+ {{IrcTagKey("v\\/e\\/n\\/d\\/o\\/r", "tag"), "b"}},
+ "",
+ "foo"));
}
TEST(IrcDecoderTest, with_escaped_tags)
{"bar", "baz", " "})).data());
}
+TEST(IrcEncoderTest, tags_with_invalid_vendor)
+{
+ EXPECT_STRCASEEQ(
+ "@a=b foo",
+ write(IrcMessage(
+ {{IrcTagKey("a"), "b"}},
+ "",
+ "foo")).data());
+ EXPECT_STRCASEEQ(
+ "@example.com/a=b foo",
+ write(IrcMessage(
+ {{IrcTagKey("example.com", "a"), "b"}},
+ "",
+ "foo")).data());
+ EXPECT_STRCASEEQ(
+ "@example.com/subfolder/to/a=b foo",
+ write(IrcMessage(
+ {{IrcTagKey("example.com/subfolder/to", "a"), "b"}},
+ "",
+ "foo")).data());
+ EXPECT_STRCASEEQ(
+ "@v\\/e\\/n\\/d\\/o\\/r/tag=b foo",
+ write(IrcMessage(
+ {{IrcTagKey("v\\/e\\/n\\/d\\/o\\/r", "tag"), "b"}},
+ "",
+ "foo")).data());
+}
+
TEST(IrcEncoderTest, tags_with_escaped_values)
{
std::vector<std::string> expected{