From fb6912da20b377be33ea82442579a0244f27ad37 Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Sun, 29 Apr 2018 16:23:53 +0200 Subject: [PATCH] Allow spaces in filenames (#1212) --- src/Asset.js | 5 ++++- src/assets/HTMLAsset.js | 2 +- test/html.js | 16 ++++++++++++++++ test/integration/resolve-spaces/index.html | 6 ++++++ test/integration/resolve-spaces/other page.html | 6 ++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/integration/resolve-spaces/index.html create mode 100644 test/integration/resolve-spaces/other page.html diff --git a/src/Asset.js b/src/Asset.js index ad3df555267..92d1d4b03bd 100644 --- a/src/Asset.js +++ b/src/Asset.js @@ -88,7 +88,10 @@ class Asset { } const parsed = URL.parse(url); - const resolved = path.resolve(path.dirname(from), parsed.pathname); + const resolved = path.resolve( + path.dirname(from), + decodeURIComponent(parsed.pathname) + ); this.addDependency( './' + path.relative(path.dirname(this.name), resolved), Object.assign({dynamic: true}, opts) diff --git a/src/assets/HTMLAsset.js b/src/assets/HTMLAsset.js index fca2532e0f7..0c8ea84e8a9 100644 --- a/src/assets/HTMLAsset.js +++ b/src/assets/HTMLAsset.js @@ -87,7 +87,7 @@ class HTMLAsset extends Asset { } processSingleDependency(path, opts) { - let assetPath = this.addURLDependency(decodeURIComponent(path), opts); + let assetPath = this.addURLDependency(path, opts); if (!isURL(assetPath)) { assetPath = urlJoin(this.options.publicURL, assetPath); } diff --git a/test/html.js b/test/html.js index 10cbd4212d2..7674010e415 100644 --- a/test/html.js +++ b/test/html.js @@ -560,4 +560,20 @@ describe('html', function() { ] }); }); + + it('should resolve assets containing spaces', async function() { + let b = await bundle(__dirname + '/integration/resolve-spaces/index.html'); + + assertBundleTree(b, { + name: 'index.html', + assets: ['index.html'], + childBundles: [ + { + type: 'html', + assets: ['other page.html'], + childBundles: [] + } + ] + }); + }); }); diff --git a/test/integration/resolve-spaces/index.html b/test/integration/resolve-spaces/index.html new file mode 100644 index 00000000000..ea07161b9f6 --- /dev/null +++ b/test/integration/resolve-spaces/index.html @@ -0,0 +1,6 @@ + + + + other page + + \ No newline at end of file diff --git a/test/integration/resolve-spaces/other page.html b/test/integration/resolve-spaces/other page.html new file mode 100644 index 00000000000..05256dff74f --- /dev/null +++ b/test/integration/resolve-spaces/other page.html @@ -0,0 +1,6 @@ + + + + index + + \ No newline at end of file