-
-
Notifications
You must be signed in to change notification settings - Fork 608
unescaped urls are being passed to downstream loaders #1048
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
Comments
Please provide configuration, you can setup loader before |
Nothing special about the loader configuration: {
module: {
rules: [
{
test: /\.svg$/,
loader: require.resolve("../loaders/CustomSvgLoader"),
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractWithCleanupPlugin.loader,
},
{
loader: "css-loader",
},
],
},
],
},
} |
Thanks i will look at that in near future |
Here the interesting use case, remember what Let's look on the specification - https://drafts.csswg.org/css-values-3/#urls.
According the specification developers can escape some characters in URL. But when you use Other example, how web servers work: index.html <style>
div {
background: url("./image.php?foo=rgba(0%2C%200%2C%200%2C%200.5)")
}
</style>
<div>
TEXT
</div> index.js const express = require('express');
const bodyParser = require('body-parser');
const url = require('url');
const querystring = require('querystring');
let app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Function to handle the root path
app.get('*', async function(req, res) {
// You will see `{ foo: 'rgba(0, 0, 0, 0.5)' }`
console.log(req.query);
res.send('Hello World!');
});
let server = app.listen(8080, function() {
console.log('Server is listening on port 8080');
}); Let's look how ES index.html
index.js console.log(import.meta);
const url = new URL(import.meta.url);
console.log(url);
// You will see `rgba(0, 0, 0, 0.5)`
console.log(url.searchParams.get('color'));
export default 'HERE'; server.js var express = require('express')
var serveStatic = require('serve-static')
var app = express()
app.use(serveStatic('.', { 'index': ['index.html', 'default.htm'] }))
app.listen(3000) Other example: index.html
A browser request So we should covert all escaped characters to real characters when we do request. My recommendations:
Also Feel free to leave feedback |
Thanks for the detailed analysis, I appreciate that. |
Code
The "css-loader" processes our css files, our custom loader processes svg files.
Example CSS processed by the css-loader
Code of the custom downstream loader processing the svg (and its query parameters):
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:
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:
The text was updated successfully, but these errors were encountered: