From 984794eb1ecc094c7750c068f7cd6aab719aced4 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 6 May 2020 01:07:06 -0400 Subject: [PATCH] fix #983 --- irc/client_lookup_set.go | 2 +- irc/client_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/irc/client_lookup_set.go b/irc/client_lookup_set.go index 6d9834f9..6db2384d 100644 --- a/irc/client_lookup_set.go +++ b/irc/client_lookup_set.go @@ -452,7 +452,7 @@ func (set *UserMaskSet) setRegexp() { set.RUnlock() if index > 0 { - expr := "^" + strings.Join(maskExprs, "|") + "$" + expr := "^(" + strings.Join(maskExprs, "|") + ")$" re, _ = regexp.Compile(expr) } diff --git a/irc/client_test.go b/irc/client_test.go index b9c6e27b..7cfeaabf 100644 --- a/irc/client_test.go +++ b/irc/client_test.go @@ -27,3 +27,32 @@ func BenchmarkGenerateBatchID(b *testing.B) { session.generateBatchID() } } + +func TestUserMasks(t *testing.T) { + var um UserMaskSet + + if um.Match("horse_!user@tor-network.onion") { + t.Error("bad match") + } + + um.Add("_!*@*", "x", "x") + if !um.Match("_!user@tor-network.onion") { + t.Error("failure to match") + } + if um.Match("horse_!user@tor-network.onion") { + t.Error("bad match") + } + + um.Add("beer*!*@*", "x", "x") + if !um.Match("beergarden!user@tor-network.onion") { + t.Error("failure to match") + } + if um.Match("horse_!user@tor-network.onion") { + t.Error("bad match") + } + + um.Add("horse*!user@*", "x", "x") + if !um.Match("horse_!user@tor-network.onion") { + t.Error("failure to match") + } +}