Make kms uri compatible with Go 1.17.
Go 1.17 introduces a change in the net/url package disallowing the use of semicolon (;) in URL queries. We used url.ParseQuery to decode the opaque string that is semicolon separated. This change replaces the semicolon with ampersands before decoding it.
This commit is contained in:
parent
a864f0134d
commit
abd78e2d2a
2 changed files with 28 additions and 1 deletions
|
@ -59,7 +59,9 @@ func Parse(rawuri string) (*URI, error) {
|
||||||
if u.Scheme == "" {
|
if u.Scheme == "" {
|
||||||
return nil, errors.Errorf("error parsing %s: scheme is missing", rawuri)
|
return nil, errors.Errorf("error parsing %s: scheme is missing", rawuri)
|
||||||
}
|
}
|
||||||
v, err := url.ParseQuery(u.Opaque)
|
// Starting with Go 1.17 url.ParseQuery returns an error using semicolon as
|
||||||
|
// separator.
|
||||||
|
v, err := url.ParseQuery(strings.ReplaceAll(u.Opaque, ";", "&"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error parsing %s", rawuri)
|
return nil, errors.Wrapf(err, "error parsing %s", rawuri)
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,3 +274,28 @@ func TestURI_Pin(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestURI_String(t *testing.T) {
|
||||||
|
mustParse := func(s string) *URI {
|
||||||
|
u, err := Parse(s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
uri *URI
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"ok new", New("yubikey", url.Values{"slot-id": []string{"9a"}, "foo": []string{"bar"}}), "yubikey:foo=bar;slot-id=9a"},
|
||||||
|
{"ok parse", mustParse("yubikey:slot-id=9a;foo=bar?bar=zar"), "yubikey:slot-id=9a;foo=bar?bar=zar"},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := tt.uri.String(); got != tt.want {
|
||||||
|
t.Errorf("URI.String() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue