diff --git a/id.go b/id.go index b78343e..8f0b3e4 100644 --- a/id.go +++ b/id.go @@ -47,7 +47,7 @@ var ( // LocatorPattern is the precompiled regular expression that all locators must match. LocatorPattern = regexp.MustCompile( - `^(?P(?i)mac|uuid|dns|serial|event|self):(?P[^/]+)?(?P/[^/]+)?(?P/[^/]+)?`, + `^(?P(?i)mac|uuid|dns|serial|event|self):(?P[^/]+)?(?P/[^/]+)?(?P.+)?`, ) ) @@ -152,10 +152,18 @@ func ParseLocator(locator string) (Locator, error) { // If the locator is a device identifier, then we need to parse it. switch l.Scheme { - case SchemeDNS, SchemeEvent: + case SchemeDNS: if l.Authority == "" { return Locator{}, ErrorInvalidLocator } + case SchemeEvent: + if l.Authority == "" { + return Locator{}, ErrorInvalidLocator + } + if l.Service != "" { + l.Ignored = "/" + l.Service + l.Ignored + l.Service = "" + } case SchemeMAC, SchemeUUID, SchemeSerial, SchemeSelf: id, err := makeDeviceID(l.Scheme, l.Authority) if err != nil { @@ -187,10 +195,10 @@ func (l Locator) String() string { if l.Service != "" { buf.WriteString("/") buf.WriteString(l.Service) + } - if l.Ignored != "" { - buf.WriteString(l.Ignored) - } + if l.Ignored != "" { + buf.WriteString(l.Ignored) } return buf.String() diff --git a/id_test.go b/id_test.go index b843dba..d52e43a 100644 --- a/id_test.go +++ b/id_test.go @@ -142,22 +142,23 @@ func TestParseLocator(t *testing.T) { }, }, { description: "locator with service", - locator: "DNS:foo.bar.com/service", - str: "dns:foo.bar.com/service", + locator: "DNS:foo.bar.com/service/ignored/really/really/ignored", + str: "dns:foo.bar.com/service/ignored/really/really/ignored", want: Locator{ Scheme: SchemeDNS, Authority: "foo.bar.com", Service: "service", + Ignored: "/ignored/really/really/ignored", }, }, { description: "locator with service everything", - locator: "event:something/service/ignored", - str: "event:something/service/ignored", + locator: "event:event_name/ignored/really/really/ignored", + str: "event:event_name/ignored/really/really/ignored", want: Locator{ Scheme: SchemeEvent, - Authority: "something", - Service: "service", - Ignored: "/ignored", + Authority: "event_name", + Service: "", + Ignored: "/ignored/really/really/ignored", }, }, { description: "self locator with service", @@ -170,12 +171,12 @@ func TestParseLocator(t *testing.T) { }, }, { description: "self locator with service everything", - locator: "self:/service/ignored", - str: "self:/service/ignored", + locator: "self:/service/ignored/really/really/ignored", + str: "self:/service/ignored/really/really/ignored", want: Locator{ Scheme: SchemeSelf, Service: "service", - Ignored: "/ignored", + Ignored: "/ignored/really/really/ignored", ID: "self:", }, },