Skip to content

unescaped urls are being passed to downstream loaders #1048

Closed
@aholtkamp

Description

@aholtkamp
  • Operating System: Linux Mint 18.3
  • Node Version: 10.16.0
  • NPM Version: Yarn 1.19.2
  • webpack Version: 4.41.5
  • css-loader Version: 3.4.2

Code

The "css-loader" processes our css files, our custom loader processes svg files.

Example CSS processed by the css-loader

div {
  background-image: url("my-special-stuff.svg?color=rgba(0%2C%200%2C%200%2C%200.5)&foo=bar");
}

Code of the custom downstream loader processing the svg (and its query parameters):

const loaderUtils = require("loader-utils");

module.exports = function(originalData) {
  let transformedData = originalData;
  if (this.resourceQuery) {
    const queryParams = loaderUtils.parseQuery(this.resourceQuery);
    // do something with the queryParams...
    // ...
  }
  return transformedData;
}

Expected Behavior

When an url contains a query string the query string should not be changed if the css-loader replaces the url statement.

Before the changes in #1016:
this.resourceQuery was "?color=rgba(0%2C%200%2C%200%2C%200.5)&foo=bar"

The resulting queryParams has looked as follows:

{
  "color": "rgba(0, 0, 0, 0.5)",
  "foo": "bar"
}

Actual Behavior

The uri components are decoded before being passed to the corresponding loader.

this.resourceQuery is now "?rgba(0, 0, 0, 0.5)"

As loaderUtils.parseQuery splits by ("&" and ",") this leads to:

{
  "color": "rgba(0",
  "0": true,
  "0.5)": true,
  "foo": "bar"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions