Skip to content

Commit

Permalink
fix "+" characters in data URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 7, 2021
1 parent eb414db commit 384d679
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/bundler/bundler_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,22 @@ func TestLoaderDataURLTextJavaScriptCannotImport(t *testing.T) {
})
}

// The "+" character must not be interpreted as a " " character
func TestLoaderDataURLTextJavaScriptPlusCharacter(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
import "data:text/javascript,console.log(1+2)";
`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
AbsOutputDir: "/out",
},
})
}

func TestLoaderDataURLApplicationJSON(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
Expand Down
6 changes: 6 additions & 0 deletions internal/bundler/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,12 @@ console.log(123);
// <data:text/javascript;charset=UTF-8;base64,Y29uc29sZS5sb2coMjM0KQ...>
console.log(234);

================================================================================
TestLoaderDataURLTextJavaScriptPlusCharacter
---------- /out/entry.js ----------
// <data:text/javascript,console.log(1+2)>
console.log(1 + 2);

================================================================================
TestLoaderDataURLUnknownMIME
---------- /out/entry.js ----------
Expand Down
2 changes: 1 addition & 1 deletion internal/resolver/dataurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (parsed DataURL) DecodeData() (string, error) {
}

// Try to read percent-escaped data
content, err := url.QueryUnescape(parsed.data)
content, err := url.PathUnescape(parsed.data)
if err != nil {
return "", fmt.Errorf("Could not decode percent-escaped data: %s", err.Error())
}
Expand Down

0 comments on commit 384d679

Please sign in to comment.