Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails when resource name contains percent encoded character #221

Closed
IronGeek opened this issue Aug 26, 2023 · 0 comments · Fixed by #222
Closed

Build fails when resource name contains percent encoded character #221

IronGeek opened this issue Aug 26, 2023 · 0 comments · Fixed by #222

Comments

@IronGeek
Copy link
Contributor

This might be a bit of an edge cases, but SubresourceIntegrityPlugin cause build to fail when resource name contains percent encoded characters.

This will have a higher chances of happening when SubresourceIntegrityPlugin is used with HtmlWebpackPlugin; since apparently HtmlWebpackPlugin is encoding the resource filenames on purpose (see: jantimon/html-webpack-plugin/issues/1771, and jantimon/html-webpack-plugin/issues/1254)

For example, build will fail with the following webpack configuration:

Here the entry name contains character which will be URL encoded (by HtmlWebpackPlugin), in real-life scenario, the percent encoded names will probably come from user-added resources that is imported somewhere in the project code and pass-through HtmlWebpackPlugin)

const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  entry: {
    "why 1+1=2?": "./index.js",
  },
  output: {
    crossOriginLoading: "anonymous",
  },
  plugins: [
    new SubresourceIntegrityPlugin({
      hashFuncNames: ["sha256"],
      enabled: true,
    }),
    new HtmlWebpackPlugin()
  ],
};
assets by status 882 bytes [cached] 2 assets
runtime modules 0 bytes 1 module
./index.js 19 bytes [built] [code generated]

ERROR in   Error: ENOENT: no such file or directory, open '/home/username/some/folder/dist/why%201%2B1%3D2?.js'
  
  - node:fs:602 Object.openSync
    node:fs:602:3
  
  - node:fs:470 readFileSync
    node:fs:470:35
  
  - plugin.js:157 Plugin.processTag
    [issue-xxx]/[webpack-subresource-integrity]/dist/cjs/plugin.js:157:100
  
  - Array.forEach
  
  - plugin.js:185 Plugin.handleHwpBodyTags
    [issue-xxx]/[webpack-subresource-integrity]/dist/cjs/plugin.js:185:39
  
  - index.js:86 SubresourceIntegrityPlugin.<anonymous>
    [issue-xxx]/[webpack-subresource-integrity]/dist/cjs/index.js:86:28
  
  - Generator.next
  
  - index.js:14 
    [issue-xxx]/[webpack-subresource-integrity]/dist/cjs/index.js:14:71
  
  - new Promise
  
  - index.js:10 __awaiter
    [issue-xxx]/[webpack-subresource-integrity]/dist/cjs/index.js:10:12

Tested with:

  • html-webpack-plugin: 5.5.3
  • webpack: 5.88.2
  • webpack-subresource-integrity: 5.2.0-rc.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant