Skip to content

v5 not omitting null/undefined tag attribute  #1597

@themgoncalves

Description

@themgoncalves

Current behaviour 💣

The issue is related to the output of html tag's attribute with null value, which was being suppressed in the previous versions.

This behaviour is particularly not wanted, and at some extension, harmful as in my case.

My application is set to use and validate Sub Resource Integrity (aka integrity attribute), which by definition should always contain a value, otherwise, it must be suppressed from the output.

<script defer="defer" src="https://www.googletagmanager.com/gtag/js?id=[GA_ID]" integrity="null" crossorigin="anonymous"></script>

Expected behaviour ☀️

Suppression of null/undefined tags, as on v4.

<script defer="defer" src="https://www.googletagmanager.com/gtag/js?id=[GA_ID]" crossorigin="anonymous"></script>

Reproduction Example 👾

This is the base setup:

    new SriPlugin({
      hashFuncNames: ['sha256', 'sha384', 'sha512'],
      enabled: isProd,
    }),
    new HtmlWebpackPlugin({
      template: './src/index.html',
      title: pkg.title,
      inject: true,
      minify: {
        collapseWhitespace: true,
        preserveLineBreaks: false,
      },
    }),
    new HtmlWebpackTagsPlugin({
      append: false,
      usePublicPath: false,
      scripts: [
        {
          path: `https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID || 'foo'}`,
          attributes: { async: true, integrity: false },
        },
      ],
    }),

Environment 🖥

  • Node.js: v14.11.0
  • darwin: 20.3.0
  • webpack: v5.21.2
  • webpack-subresource-integrity: v1.5.2
  • html-webpack-tags-plugin: v3.0.0

And of course, html-webpack-plugin: v5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions