GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: keep names in generated comments and URLs from being read as code or loaders by alexander-akait · Pull Request #23153 · webpack/webpack

fix: keep names in generated comments and URLs from being read as code or loaders #23153

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.

Sign up for GitHub

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

Merged
alexander-akait merged 12 commits into main from fix/comment-and-request-escaping
Nov 6, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix: keep names in generated comments and URLs from being read as code or loaders #23153

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
5bc39bb
fix(template): keep line breaks in generated block comments on one line
alexander-akait Nov 5, 2026
5a3a37c
fix(concatenate-modules): keep line breaks in names inside generated …
alexander-akait Nov 5, 2026
54d0a59
fix(devtool): encode the module id in the eval-source-map sourceURL c…
alexander-akait Nov 5, 2026
f670d40
fix(devtool): keep the sourceMappingURL comment intact for unusual as…
alexander-akait Nov 5, 2026
a12dea6
fix(context): keep the request of an unresolved glob entry inside its…
alexander-akait Nov 5, 2026
a3decf0
fix(css): escape CR and FF in CSS url() strings
alexander-akait Nov 5, 2026
b97c9d6
fix(html): treat a URL in HTML or a web manifest as a file URL, not a…
alexander-akait Nov 5, 2026
65149f4
fix(schemes): read requests in a cached http(s) response as file name…
alexander-akait Nov 5, 2026
2bf1456
chore: add changeset
alexander-akait Nov 5, 2026
4e44154
fix(html): match URL hint rules against the URL before escaping it
alexander-akait Nov 5, 2026
0d03e1a
fix(devtool): keep the path separator when encoding a comment end in …
alexander-akait Nov 5, 2026
063295a
test: keep LF line endings in the build-http cache fixture on Windows
alexander-akait Nov 5, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
fix(devtool): keep the sourceMappingURL comment intact for unusual as…
…set names

Percent-encode line terminators and `*/` in the [url] of the
sourceMappingURL comment, and decide on the block comment form by the
asset path without its query, so a query ending in ".css" no longer
switches a JavaScript asset to it.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait committed Nov 5, 2026
commit f670d4088f6fac5ea469d9be2e0087f6da4f9fc2

There are no files selected for viewing

16 changes: 14 additions & 2 deletions 16 lib/devtool/SourceMapDevToolPlugin.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,22 @@ const generateDebugId = require("./generateDebugId");

const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g;
const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i;
const CSS_EXTENSION_DETECT_REGEXP = /\.css(?:$|\?)/i;
// The written file ends at the first `?` or `#`, so a query never makes it CSS.
const CSS_EXTENSION_DETECT_REGEXP = /^[^?#]*\.css(?:[?#]|$)/i;
const MAP_URL_COMMENT_REGEXP = /\[map\]/g;
const URL_COMMENT_REGEXP = /\[url\]/g;
const URL_FORMATTING_REGEXP = /^\n\/\/(.*)$/;
const URL_COMMENT_END_REGEXP = /\*\/|[\n\r\u2028\u2029]/g;

/**
* Percent-encodes line terminators and comment ends that would close the comment around a source map url.
* @param {string} url source map url
* @returns {string} url that stays inside the comment
*/
const encodeSourceMappingUrl = (url) =>
url.replace(URL_COMMENT_END_REGEXP, (match) =>
match === "*/" ? "*%2F" : encodeURIComponent(match)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

);

/**
* Reset's .lastIndex of stateful Regular Expressions
Expand Down Expand Up @@ -911,7 +923,7 @@ class SourceMapDevToolPlugin {
asset = new ConcatSource(
asset,
compilation.getPath(currentSourceMappingURLComment, {
url: sourceMapUrl,
url: encodeSourceMappingUrl(sourceMapUrl),
...pathParams
})
);
Expand Down
1 change: 1 addition & 0 deletions 1 test/configCases/source-map/source-mapping-url-line-break/chunk.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "chunk";
25 changes: 25 additions & 0 deletions 25 test/configCases/source-map/source-mapping-url-line-break/index.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require("fs");
const path = require("path");

it("should load a chunk whose name contains line breaks", () =>
import(/* webpackChunkName: "a\nb\rc\u2028d\u2029e" */ "./chunk").then(
(ns) => {
expect(ns.default).toBe("chunk");
const source = fs.readFileSync(
path.join(__dirname, "a\nb\rc\u2028d\u2029e.js"),
"utf-8"
);
expect(source).toMatch(
/\n\/\/# sourceMappingURL=a%0Ab%0Dc%E2%80%A8d%E2%80%A9e\.js\.map$/
);
}
));

it("should keep a line comment for a JavaScript asset whose query ends in .css", () => {
const file = path.join(__dirname, "other.js");
expect(() => __non_webpack_require__(file)).not.toThrow();
const source = fs.readFileSync(file, "utf-8");
expect(source).toMatch(
/\n\/\/# sourceMappingURL=[^\n]*other\.js\.map\?a\*%2Fb\.css$/
);
});
1 change: 1 addition & 0 deletions 1 test/configCases/source-map/source-mapping-url-line-break/other.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "other";
7 changes: 7 additions & 0 deletions 7 test/configCases/source-map/source-mapping-url-line-break/test.config.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = {
findBundle() {
return ["main.js"];
}
};
4 changes: 4 additions & 0 deletions 4 test/configCases/source-map/source-mapping-url-line-break/test.filter.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";

// Windows file names cannot hold a line break, which the chunk name puts there.
module.exports = () => process.platform !== "win32";
17 changes: 17 additions & 0 deletions 17 test/configCases/source-map/source-mapping-url-line-break/webpack.config.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
devtool: "source-map",
entry: {
main: "./index.js",
other: "./other.js"
},
output: {
// The query ends in ".css", but the asset is still JavaScript.
filename: (pathData) =>
pathData.chunk.name === "other" ? "other.js?a*/b.css" : "[name].js",
chunkFilename: "[name].js"
}
};
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.