diff --git a/index.js b/index.js index 64ff1437..3dcfbde9 100644 --- a/index.js +++ b/index.js @@ -604,7 +604,7 @@ class HtmlWebpackPlugin { // E.g. bundle.js -> /bundle.js?hash const entryPointPublicPaths = entryPointFiles .map(chunkFile => { - const entryPointPublicPath = publicPath + chunkFile; + const entryPointPublicPath = publicPath + this.urlencodePath(chunkFile); return this.options.hash ? this.appendHash(entryPointPublicPath, compilationHash) : entryPointPublicPath; @@ -926,6 +926,16 @@ class HtmlWebpackPlugin { return url + (url.indexOf('?') === -1 ? '?' : '&') + hash; } + /** + * Encode each path component using `encodeURIComponent` as files can contain characters + * which needs special encoding in URLs like `+ `. + * + * @param {string} filePath + */ + urlencodePath (filePath) { + return filePath.split('/').map(encodeURIComponent).join('/'); + } + /** * Helper to return the absolute template path with a fallback loader * @param {string} template diff --git a/spec/basic.spec.js b/spec/basic.spec.js index fc8dd148..2092c5dc 100644 --- a/spec/basic.spec.js +++ b/spec/basic.spec.js @@ -104,6 +104,18 @@ describe('HtmlWebpackPlugin', () => { }, [/
[\s]*