diff --git a/FILTER.md b/FILTER.md index fbfc5039..0e24a101 100644 --- a/FILTER.md +++ b/FILTER.md @@ -219,6 +219,10 @@ Group-text messages look like `SenderName: message text` after decryption. `DF)EQ4X:: hello` has the sender `DF)EQ4X:`, and a colon-space in the text (`Alice: note: hi`) does not split it. A message with no `: ` at all (`Alice:hi`) still splits on the bare colon. +- A name that itself contains `: ` cannot be recovered — the first `: ` is + always the boundary, exactly as the official client splits it. So + `some: name: test: this is a test: hello` has the sender `some` and the text + `name: test: this is a test: hello`; use `text=` as well to target the rest. - Matching is **case-sensitive**, and a pattern matches *anywhere* in the field unless you anchor it. The three most common shapes, at a glance: diff --git a/test/test_packet_filter/test_packet_filter.cpp b/test/test_packet_filter/test_packet_filter.cpp index 6792ee0f..62c666dd 100644 --- a/test/test_packet_filter/test_packet_filter.cpp +++ b/test/test_packet_filter/test_packet_filter.cpp @@ -945,6 +945,28 @@ TEST_F(FilterTest, TextColonSpaceDoesNotSplitSender) { FILTER_ACT_DROP); } +// A name that itself contains ": " is inherently ambiguous. The official +// client splits on the first ": " too, so "some: name: test: ..." has the +// sender "some" — pin that so it stays deliberate rather than drifting. +TEST_F(FilterTest, SenderNameWithColonSpaceSplitsAtFirstDelimiter) { + auto pkt = makePacket(ROUTE_TYPE_FLOOD, PAYLOAD_TYPE_GRP_TXT, 20); + auto chan = channelFromStore(filter, 0); + + expectOk(filter, "add sender=^some$ text=\"^name: test: this is\""); + auto payload = makeGroupText("some: name: test", "this is a test: hello"); + EXPECT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, payload.data, + payload.len, nullptr), + FILTER_ACT_DROP); + + // the full intended name is not recoverable, so an anchored pattern for it + // cannot match + filter.clearRules(); + expectOk(filter, "add sender=\"^some: name: test$\""); + EXPECT_EQ(filter.checkContent(&pkt, PAYLOAD_TYPE_GRP_TXT, chan, payload.data, + payload.len, nullptr), + FILTER_ACT_ALLOW); +} + TEST_F(FilterTest, SenderRegexIsUnanchoredByDefault) { expectOk(filter, "add sender=Spam"); // substring, case-sensitive auto payload = makeGroupText("theSpamBot", "hi");