diff --git a/examples/issue-221/index.js b/examples/issue-221/index.js new file mode 100644 index 0000000..4f252c0 --- /dev/null +++ b/examples/issue-221/index.js @@ -0,0 +1 @@ +console.log("ok"); diff --git a/examples/issue-221/package.json b/examples/issue-221/package.json new file mode 100644 index 0000000..709926e --- /dev/null +++ b/examples/issue-221/package.json @@ -0,0 +1,15 @@ +{ + "name": "issue-221", + "description": "Test case for https://github.com/waysact/webpack-subresource-integrity/issues/221", + "version": "1.0.0", + "license": "MIT", + "private": true, + "devDependencies": { + "expect": "^26.6.2", + "html-webpack-plugin": ">= 5.0.0-beta.1", + "nyc": "*", + "webpack": "^5.44.0", + "webpack-cli": "4", + "webpack-subresource-integrity": "*" + } +} diff --git a/examples/issue-221/webpack.config.js b/examples/issue-221/webpack.config.js new file mode 100644 index 0000000..6e036c7 --- /dev/null +++ b/examples/issue-221/webpack.config.js @@ -0,0 +1,28 @@ +const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); +const expect = require("expect"); + +module.exports = { + entry: { + "why 1+1=2?": "./index.js", + }, + output: { + crossOriginLoading: "anonymous", + }, + plugins: [ + new SubresourceIntegrityPlugin({ + hashFuncNames: ["sha256"], + enabled: true, + }), + new HtmlWebpackPlugin(), + { + apply: (compiler) => { + compiler.hooks.done.tap("wsi-test", (stats) => { + expect( + stats.toJson().assets.find((asset) => asset.name == "why 1+1=2?.js") + ).toHaveProperty("integrity"); + }); + }, + }, + ], +}; diff --git a/webpack-subresource-integrity/src/plugin.ts b/webpack-subresource-integrity/src/plugin.ts index 8d363b4..e617de0 100644 --- a/webpack-subresource-integrity/src/plugin.ts +++ b/webpack-subresource-integrity/src/plugin.ts @@ -238,7 +238,7 @@ export class Plugin { */ private hwpAssetPath = (src: string): string => { assert(this.hwpPublicPath !== null, "Missing HtmlWebpackPlugin publicPath"); - return relative(this.hwpPublicPath, src); + return relative(this.hwpPublicPath, decodeURIComponent(src)); }; /** diff --git a/yarn.lock b/yarn.lock index b489c0d..74aab7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5518,6 +5518,19 @@ __metadata: languageName: unknown linkType: soft +"issue-221@workspace:examples/issue-221": + version: 0.0.0-use.local + resolution: "issue-221@workspace:examples/issue-221" + dependencies: + expect: ^26.6.2 + html-webpack-plugin: ">= 5.0.0-beta.1" + nyc: "*" + webpack: ^5.44.0 + webpack-cli: 4 + webpack-subresource-integrity: "*" + languageName: unknown + linkType: soft + "istanbul-lib-coverage@npm:^3.0.0, istanbul-lib-coverage@npm:^3.2.0": version: 3.2.0 resolution: "istanbul-lib-coverage@npm:3.2.0"