Skip to content

Commit 986efee

Browse files
fix(html): reject srcset descriptors after a zero density (#22741)
1 parent c27ca7b commit 986efee

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Reject a second `srcset` descriptor after a `0x` density descriptor.

‎lib/html/syntax-parser.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14920,7 +14920,7 @@ const parseSrcset = (input) => {
1492014920
lastChar === SMALL_LETTER_W
1492114921
) {
1492214922
// If width and density are not both absent, then let error be yes.
14923-
if (width || density) {
14923+
if (width !== undefined || density !== undefined) {
1492414924
pError = true;
1492514925
}
1492614926

@@ -14943,7 +14943,11 @@ const parseSrcset = (input) => {
1494314943
) {
1494414944
// If width, density and future-compat-h are not all absent, then let error
1494514945
// be yes.
14946-
if (width || density || height) {
14946+
if (
14947+
width !== undefined ||
14948+
density !== undefined ||
14949+
height !== undefined
14950+
) {
1494714951
pError = true;
1494814952
}
1494914953

@@ -14965,7 +14969,7 @@ const parseSrcset = (input) => {
1496514969
lastChar === SMALL_LETTER_H
1496614970
) {
1496714971
// If height and density are not both absent, then let error be yes.
14968-
if (height || density) {
14972+
if (height !== undefined || density !== undefined) {
1496914973
pError = true;
1497014974
}
1497114975

‎test/unitCases/HtmlSyntax.unittest.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9357,6 +9357,19 @@ describe("parseSrcset", () => {
93579357
expect(() => parseSrcset("a.png -1x")).toThrow(/Invalid srcset descriptor/);
93589358
});
93599359

9360+
it("should throw on a descriptor after a zero density descriptor", () => {
9361+
expect(parseSrcset("a.png 0x")).toEqual([["a.png", 0, 5]]);
9362+
expect(() => parseSrcset("a.png 0x 1x")).toThrow(
9363+
/Invalid srcset descriptor/
9364+
);
9365+
expect(() => parseSrcset("a.png 0x 1w")).toThrow(
9366+
/Invalid srcset descriptor/
9367+
);
9368+
expect(() => parseSrcset("a.png 0x 1h")).toThrow(
9369+
/Invalid srcset descriptor/
9370+
);
9371+
});
9372+
93609373
it("should throw on conflicting descriptors", () => {
93619374
expect(() => parseSrcset("a.png 480w 2x")).toThrow(
93629375
/Invalid srcset descriptor/

0 commit comments

Comments
 (0)