Skip to content

Commit

Permalink
Decode UTF-8 properly from URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 28, 2025
1 parent 6c49a1f commit 7ca70f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func DecodeURL(b []byte) []byte {
c = c<<4 + int(b[j]-'a') + 10
}
}
if j == i+3 && c < 128 {
if j == i+3 {
b[i] = byte(c)
b = append(b[:i+1], b[i+3:]...)
}
Expand Down
3 changes: 2 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestParseDataURI(t *testing.T) {
{"data:;base64,()", "", "", base64.CorruptInputError(0)},
{"data:image/svg+xml,%3Cpath%20stroke-width='9.38%'/%3E", "image/svg+xml", "<path stroke-width='9.38%'/>", nil},
{"data:,%ii", "text/plain", "%ii", nil},
{"data:image/svg&#43;xml,%e2%ad%90", "image/svg&#43;xml", "\u2b50", nil},
}
for _, tt := range dataURITests {
t.Run(tt.dataURI, func(t *testing.T) {
Expand Down Expand Up @@ -283,7 +284,7 @@ func TestDecodeURL(t *testing.T) {
expected string
}{
{"%20%3F%7E", " ?~"},
{"%80", "%80"},
{"%80", "\x80"},
{"%2B%2b", "++"},
{"%' ", "%' "},
{"a+b", "a b"},
Expand Down

0 comments on commit 7ca70f9

Please sign in to comment.