Skip to content

Commit

Permalink
fix: percent encode handling in URL opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Dec 28, 2022
1 parent db0bce4 commit ca414e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib-ayd/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ParseURL(s string) (*URL, error) {
return nil, err
}
if u.Opaque == "" && barePathInOpaque(s) {
u.Opaque = u.Path
u.Opaque = escapeFragment(u.Path)
u.Path = ""
}
return (*URL)(u), nil
Expand Down
10 changes: 10 additions & 0 deletions lib-ayd/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func TestParseURL(t *testing.T) {
{"exec:/path/to/file", "exec:/path/to/file", "", "", "/path/to/file"},
{"source+exec:/path/to/file", "source+exec:/path/to/file", "", "", "/path/to/file"},
{"https://example.com/path/to", "https://example.com/path/to", "example.com", "/path/to", ""},
{"foo:/%00Aaあ亜%01", "foo:/%00Aaあ亜%01", "", "", "/%00Aaあ亜%01"},
{"foo:%00Aaあ亜%01", "foo:%00Aaあ亜%01", "", "", "%00Aaあ亜%01"},
{"foo://bar/%00Aaあ亜%01", "foo://bar/%00Aa%E3%81%82%E4%BA%9C%01", "bar", "/\x00Aaあ亜\x01", ""},
}

for _, tt := range tests {
Expand Down Expand Up @@ -71,6 +74,10 @@ func TestURL_String(t *testing.T) {
tt := tt
t.Run(tt.Input.String(), func(t *testing.T) {
result := tt.Input.String()

t.Logf("input: %#v", tt.Input)
t.Logf("output: %#v", result)

if tt.Output != result {
t.Errorf("expected output is %s but got %s", tt.Output, result)
}
Expand All @@ -89,6 +96,9 @@ func TestURL_marshalAndUnmarshal(t *testing.T) {
{"a:/b/c?d=e#f", "a:/b/c?d=e#f"},
{"a://b/c?d=e#f", "a://b/c?d=e#f"},
{"a://b:c@d", "a://b:xxxxx@d"},
{"foo:%00abc%01", "foo:%00abc%01"},
{"foo:/%00abc%01", "foo:/%00abc%01"},
{"foo://bar/%00abc%01", "foo://bar/%00abc%01"},
}

for _, tt := range tests {
Expand Down

0 comments on commit ca414e8

Please sign in to comment.