From 4cdda9ff04f312d8f5bdfd56c014e29bc431c1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kopi=C3=A1s=20Csaba?= Date: Fri, 1 Sep 2023 10:19:34 +0300 Subject: [PATCH 1/2] Fix Message.Match pattern matching --- message.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/message.go b/message.go index eace8b6..605a6a8 100644 --- a/message.go +++ b/message.go @@ -89,11 +89,11 @@ func (msg Message) Match(address string, exactMatch bool) (bool, error) { if !VerifyParts(address, msg.Address) { return false, nil } - exp, err := GetRegex(msg.Address) + exp, err := GetRegex(address) if err != nil { return false, err } - return exp.MatchString(address), nil + return exp.MatchString(msg.Address), nil } // Typetags returns a padded byte slice of the message's type tags. From 5da4f27c87b821f88971458d95dad88ab6c0aa74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kopi=C3=A1s=20Csaba?= Date: Fri, 1 Sep 2023 10:50:53 +0300 Subject: [PATCH 2/2] Fix tests, rename msg.Match's first argument to be more obvious. --- dispatcher_test.go | 4 ++-- message.go | 8 ++++---- message_test.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dispatcher_test.go b/dispatcher_test.go index 10ce5d6..43a6d81 100644 --- a/dispatcher_test.go +++ b/dispatcher_test.go @@ -102,8 +102,8 @@ func TestDispatcherInvoke(t *testing.T) { t.Fatal("expected error, got nil") } badMsg := Message{Address: "/["} - if err := d.Invoke(badMsg, false); err == nil { - t.Fatal("expected error, got nil") + if err := d.Invoke(badMsg, false); err != nil { + t.Fatal("expected nil, got error") } if err := d.Invoke(Message{Address: "/bar"}, false); err != nil { t.Fatal(err) diff --git a/message.go b/message.go index 605a6a8..2c9c7b8 100644 --- a/message.go +++ b/message.go @@ -81,15 +81,15 @@ func (msg Message) Equal(other Packet) bool { } // Match returns true if the address of the OSC Message matches the given address. -func (msg Message) Match(address string, exactMatch bool) (bool, error) { +func (msg Message) Match(addressPattern string, exactMatch bool) (bool, error) { if exactMatch { - return address == msg.Address, nil + return addressPattern == msg.Address, nil } // Verify same number of parts. - if !VerifyParts(address, msg.Address) { + if !VerifyParts(addressPattern, msg.Address) { return false, nil } - exp, err := GetRegex(address) + exp, err := GetRegex(addressPattern) if err != nil { return false, err } diff --git a/message_test.go b/message_test.go index 21dea60..b38e324 100644 --- a/message_test.go +++ b/message_test.go @@ -84,8 +84,8 @@ func TestMatch(t *testing.T) { {"/path/to/method*", "/path/to/method"}, {"/path/to/m[aei]thod", "/path/to/method"}, } { - msg := Message{Address: pair[0]} - match, err := msg.Match(pair[1], false) + msg := Message{Address: pair[1]} + match, err := msg.Match(pair[0], false) if err != nil { t.Fatal(err) } @@ -113,8 +113,8 @@ func TestMatch(t *testing.T) { } msg := Message{Address: `/[`} - if _, err := msg.Match(`/a`, false); err == nil { - t.Fatalf("expected error, got nil") + if _, err := msg.Match(`/a`, false); err != nil { + t.Fatalf("expected nil, got error") } }