Skip to content

Commit

Permalink
fix #164: avoid slashes in file loader file names
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 4, 2020
1 parent b6541a8 commit a732214
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Fix slash characters in file loader ([#164](https://github.com/evanw/esbuild/pull/164))

This fixes a bug where the base64-encoded hash included in the file name could sometimes contain a `/` character. The fix is to use the base64 character set for URL-encoding, which replaces the `/` character with a `_` character.

## 0.4.4

* Fix optional chaining with TypeScript operators ([#168](https://github.com/evanw/esbuild/issues/168))
Expand Down
2 changes: 1 addition & 1 deletion internal/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func parseFile(args parseArgs) {
// but different contents from colliding
bytes := []byte(source.Contents)
hashBytes := sha1.Sum(bytes)
hash := base64.StdEncoding.EncodeToString(hashBytes[:])[:8]
hash := base64.URLEncoding.EncodeToString(hashBytes[:])[:8]
baseName = baseName[:len(baseName)-len(extension)] + "." + hash + extension

// Determine the destination folder
Expand Down
8 changes: 5 additions & 3 deletions internal/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,9 @@ func TestLoaderFile(t *testing.T) {
"/entry.js": `
console.log(require('./test.svg'))
`,
"/test.svg": "<svg></svg>",

// Use an SVG string that has a base64-encoded SHA1 has with a "/" in it
"/test.svg": "<svg>$</svg>",
},
entryPaths: []string{"/entry.js"},
parseOptions: parser.ParseOptions{
Expand All @@ -2779,10 +2781,10 @@ func TestLoaderFile(t *testing.T) {
},
},
expected: map[string]string{
"/out/test.ntXZxVw0.svg": "<svg></svg>",
"/out/test.1HOBn_hi.svg": "<svg>$</svg>",
"/out/entry.js": `// /test.svg
var require_test = __commonJS((exports, module) => {
module.exports = "test.ntXZxVw0.svg";
module.exports = "test.1HOBn_hi.svg";
});
// /entry.js
Expand Down

0 comments on commit a732214

Please sign in to comment.