Skip to content

Commit e33087c

Browse files
petetntshellscape
authored andcommitted
Use querystring.unescape to fallback to safer equivalent that does not throw on malformed URIs (#201)
Signed-off-by: petetnt <[email protected]>
1 parent e264335 commit e33087c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/GetFilenameFromUrl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var pathJoin = require("./PathJoin");
2+
var querystring = require("querystring");
23
var urlParse = require("url").parse;
34

45
function getFilenameFromUrl(publicPath, outputPath, url) {
@@ -29,8 +30,7 @@ function getFilenameFromUrl(publicPath, outputPath, url) {
2930
return false;
3031
}
3132
// and if not match, use outputPath as filename
32-
return decodeURIComponent(filename ? pathJoin(outputPath, filename) : outputPath);
33-
33+
return querystring.unescape(filename ? pathJoin(outputPath, filename) : outputPath);
3434
}
3535

3636
// support for multi-compiler configuration

test/GetFilenameFromUrl.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe("GetFilenameFromUrl", function() {
1919
outputPath: "/",
2020
publicPath: "/",
2121
expected: "/föö.js"
22+
}, {
23+
url: "/%foo%/%foo%.js", // Filenames can contain characters not allowed in URIs
24+
outputPath: "/",
25+
publicPath: "/",
26+
expected: "/%foo%/%foo%.js"
2227
}, {
2328
url: "/0.19dc5d417382d73dd190.hot-update.js",
2429
outputPath: "/",

0 commit comments

Comments
 (0)