Skip to content

Truly independent web browser

LibWeb: Clear SVG point lists when parsing invalid coordinates

Andreas Kling75017721e108
diff --git a/Libraries/LibWeb/Rust/src/svg/attribute_parser.rs b/Libraries/LibWeb/Rust/src/svg/attribute_parser.rs
index 2190fd92f8e..34ecbc581a4 100644
--- a/Libraries/LibWeb/Rust/src/svg/attribute_parser.rs
+++ b/Libraries/LibWeb/Rust/src/svg/attribute_parser.rs
@@ -76,17 +76,23 @@ fn parse_points(input: Input<'_>) -> Vec<[f32; 2]> {
let mut parser = Parser::new(input);
parser.parse_whitespace();
let mut points = Vec::new();
- loop {
- let point = match parser.parse_coordinate_pair() {
- Ok(point) => point,
- Err(()) if points.is_empty() => return Vec::new(),
- Err(()) => break,
+ while !parser.done() {
+ let Ok(x) = parser.parse_number() else {
+ return Vec::new();
};
- points.push(point);
parser.parse_optional_comma_whitespace();
- if !parser.matches_comma_whitespace() && !parser.matches_coordinate() {
+
+ // https://svgwg.org/svg2-draft/shapes.html#PolylineElementPointsAttribute
+ // In such error cases the user agent will drop the last, odd coordinate and otherwise render the shape.
+ if parser.done() {
break;
}
+
+ let Ok(y) = parser.parse_number() else {
+ return Vec::new();
+ };
+ points.push([x, y]);
+ parser.parse_optional_comma_whitespace();
}
points
}
diff --git a/Tests/LibWeb/Ref/expected/svg-polygon-with-incomplete-points-ref.html b/Tests/LibWeb/Ref/expected/svg-polygon-with-incomplete-points-ref.html
index ab577425a3c..cea119fb5de 100644
--- a/Tests/LibWeb/Ref/expected/svg-polygon-with-incomplete-points-ref.html
+++ b/Tests/LibWeb/Ref/expected/svg-polygon-with-incomplete-points-ref.html
@@ -10,9 +10,5 @@
<svg viewBox="0 0 10 10" width="100" height="100">
<polygon points="0,0 0,10 10,10" />
</svg>
-<svg viewBox="0 0 10 10" width="100" height="100">
- <polygon points="0,0 0,10 10,10" />
-</svg>
-<svg viewBox="0 0 10 10" width="100" height="100">
- <polygon points="0,0 0,10 10,10 10,0" />
-</svg>
+<svg viewBox="0 0 10 10" width="100" height="100"></svg>
+<svg viewBox="0 0 10 10" width="100" height="100"></svg>
diff --git a/Tests/LibWeb/Ref/input/svg-polygon-with-incomplete-points.html b/Tests/LibWeb/Ref/input/svg-polygon-with-incomplete-points.html
index 52f30b02024..f3dfeb80b98 100644
--- a/Tests/LibWeb/Ref/input/svg-polygon-with-incomplete-points.html
+++ b/Tests/LibWeb/Ref/input/svg-polygon-with-incomplete-points.html
@@ -25,5 +25,5 @@
<polygon points="0 0 0 10 10 10 10 invalid" />
</svg>
<svg viewBox="0 0 10 10" width="100" height="100">
- <polygon points="0,0 0,10 10,10 10,0 a complete rectangle should be drawn here" />
+ <polygon points="0,0 0,10 10,10 10,0 invalid" />
</svg>
diff --git a/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt b/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt
index 4a3b2b4f777..1447f261a56 100644
--- a/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt
+++ b/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt
@@ -1,22 +1,22 @@
polygon "0,0 1,1": 2
polygon "0,0 1,1 2": 2
polygon "0,0 1,1 2,": 2
-polygon "0,0 1,1 INVALID": 2
-polygon "0,0 +": 1
-polygon "0,0 1,+": 1
-polygon "0,0 1e+": 1
-polygon "0,0 .": 1
-polygon "0,0 1,-": 1
-polygon "0,0 1,1,,": 2
+polygon "0,0 1,1 INVALID": 0
+polygon "0,0 +": 0
+polygon "0,0 1,+": 0
+polygon "0,0 1e+": 0
+polygon "0,0 .": 0
+polygon "0,0 1,-": 0
+polygon "0,0 1,1,,": 0
polygon " ": 0
polyline "0,0 1,1": 2
polyline "0,0 1,1 2": 2
polyline "0,0 1,1 2,": 2
-polyline "0,0 1,1 INVALID": 2
-polyline "0,0 +": 1
-polyline "0,0 1,+": 1
-polyline "0,0 1e+": 1
-polyline "0,0 .": 1
-polyline "0,0 1,-": 1
-polyline "0,0 1,1,,": 2
+polyline "0,0 1,1 INVALID": 0
+polyline "0,0 +": 0
+polyline "0,0 1,+": 0
+polyline "0,0 1e+": 0
+polyline "0,0 .": 0
+polyline "0,0 1,-": 0
+polyline "0,0 1,1,,": 0
polyline " ": 0
diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.txt
index 0ee0ce23ae9..702a04cbeed 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.txt
@@ -2,10 +2,9 @@ Harness status: OK
Found 5 tests
-4 Pass
-1 Fail
+5 Pass
Pass SVGLengthList clears items when attribute value is invalid
Pass SVGNumberList clears items when attribute value is invalid
-Fail SVGPointList clears items when attribute value is invalid
+Pass SVGPointList clears items when attribute value is invalid
Pass SVGPointList truncates items when y attribute value is missing
Pass SVGTransformList clears items when attribute value is invalid
\ No newline at end of file