Skip to content

Truly independent web browser

LibWeb: Import SVG list invalid-value parsing coverage

Andreas Kling3d3a77d6c632
diff --git a/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt b/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt
new file mode 100644
index 00000000000..4a3b2b4f777
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/svg-point-list-invalid-numbers.txt
@@ -0,0 +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
+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
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
new file mode 100644
index 00000000000..0ee0ce23ae9
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 5 tests
+
+4 Pass
+1 Fail
+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 truncates items when y attribute value is missing
+Pass SVGTransformList clears items when attribute value is invalid
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/svg-point-list-invalid-numbers.html b/Tests/LibWeb/Text/input/svg-point-list-invalid-numbers.html
new file mode 100644
index 00000000000..f83b6d1828a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/svg-point-list-invalid-numbers.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script>
+ test(() => {
+ for (const name of ["polygon", "polyline"]) {
+ const element = document.createElementNS("http://www.w3.org/2000/svg", name);
+ for (const points of ["0,0 1,1", "0,0 1,1 2", "0,0 1,1 2,", "0,0 1,1 INVALID", "0,0 +", "0,0 1,+", "0,0 1e+", "0,0 .", "0,0 1,-", "0,0 1,1,,", " "]) {
+ element.setAttribute("points", points);
+ println(`${name} ${JSON.stringify(points)}: ${element.points.numberOfItems}`);
+ }
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.html b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.html
new file mode 100644
index 00000000000..748f119d16b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGList-parse-invalid-clears-items.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<title>SVG list types clear items on invalid attribute parse</title>
+<link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGLengthList">
+<link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGNumberList">
+<link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGPointList">
+<link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGTransformList">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script>
+
+test(function() {
+ const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
+ text.setAttribute("x", "10 20 30");
+
+ assert_equals(text.x.baseVal.numberOfItems, 3, "initial valid parse gives 3 items");
+
+ // Setting a partially invalid value: valid entries followed by an invalid one.
+ text.setAttribute("x", "10 20 INVALID");
+ assert_equals(text.x.baseVal.numberOfItems, 0,
+ "SVGLengthList: partially invalid attribute value should result in 0 items");
+}, "SVGLengthList clears items when attribute value is invalid");
+
+test(function() {
+ const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
+ text.setAttribute("rotate", "10 20 30");
+
+ assert_equals(text.rotate.baseVal.numberOfItems, 3, "initial valid parse gives 3 items");
+
+ // Setting a partially invalid value: valid entries followed by an invalid one.
+ text.setAttribute("rotate", "10 20 INVALID");
+ assert_equals(text.rotate.baseVal.numberOfItems, 0,
+ "SVGNumberList: partially invalid attribute value should result in 0 items");
+}, "SVGNumberList clears items when attribute value is invalid");
+
+test(function() {
+ const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
+ polygon.setAttribute("points", "0,0 100,0 100,100 0,100");
+
+ assert_equals(polygon.points.numberOfItems, 4, "initial valid parse gives 4 items");
+
+ // Setting a partially invalid value: valid point pairs followed by an invalid one.
+ polygon.setAttribute("points", "0,0 100,0 INVALID");
+ assert_equals(polygon.points.numberOfItems, 0,
+ "SVGPointList: partially invalid attribute value should result in 0 items");
+}, "SVGPointList clears items when attribute value is invalid");
+
+test(function() {
+ const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
+
+ // Valid point pairs followed by an incomplete pair.
+ polygon.setAttribute("points", "0,0 100,0 20");
+ assert_equals(polygon.points.numberOfItems, 2,
+ "SVGPointList: partially invalid attribute value should result in 2 items");
+
+ // Valid point pairs followed by an incomplete pair.
+ polygon.setAttribute("points", "0,0 100,0 20,");
+ assert_equals(polygon.points.numberOfItems, 2,
+ "SVGPointList: partially invalid attribute value should result in 2 items");
+}, "SVGPointList truncates items when y attribute value is missing");
+
+test(function() {
+ const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
+ rect.setAttribute("transform", "translate(10,20) rotate(45)");
+
+ assert_equals(rect.transform.baseVal.numberOfItems, 2, "initial valid parse gives 2 items");
+
+ // Setting a partially invalid value: valid transform followed by an invalid one.
+ rect.setAttribute("transform", "translate(10,20) INVALID");
+ assert_equals(rect.transform.baseVal.numberOfItems, 0,
+ "SVGTransformList: partially invalid attribute value should result in 0 items");
+}, "SVGTransformList clears items when attribute value is invalid");
+</script>