diff --git a/id.go b/id.go index 8f0b3e4..69d9c52 100644 --- a/id.go +++ b/id.go @@ -141,13 +141,13 @@ func ParseLocator(locator string) (Locator, error) { var l Locator - l.Scheme = strings.ToLower(match[1]) - l.Authority = match[2] + l.Scheme = strings.TrimSpace(strings.ToLower(match[1])) + l.Authority = strings.TrimSpace(match[2]) if len(match) > 3 { - l.Service = strings.TrimPrefix(match[3], "/") + l.Service = strings.TrimSpace(strings.TrimPrefix(match[3], "/")) } if len(match) > 4 { - l.Ignored = match[4] + l.Ignored = strings.TrimSpace(match[4]) } // If the locator is a device identifier, then we need to parse it. diff --git a/id_test.go b/id_test.go index d52e43a..8cb38f8 100644 --- a/id_test.go +++ b/id_test.go @@ -190,6 +190,14 @@ func TestParseLocator(t *testing.T) { Scheme: SchemeDNS, Authority: "foo.bar.com", }, + }, { + description: "event scheme (with spaces)", + locator: "event: targetedEvent ", + str: "event:targetedEvent", + want: Locator{ + Scheme: SchemeEvent, + Authority: "targetedEvent", + }, }, { description: "event scheme", locator: "event:targetedEvent", @@ -251,6 +259,14 @@ func TestParseLocator(t *testing.T) { description: "invalid self scheme", locator: "self:anything", expectedErr: ErrorInvalidDeviceName, + }, { + description: "invalid event scheme (no authority)", + locator: "event:/anything", + expectedErr: ErrorInvalidLocator, + }, { + description: "invalid event scheme (no authority and with spaces)", + locator: "event: /anything", + expectedErr: ErrorInvalidLocator, }, } for _, tc := range tests {