浏览代码

LibWeb: Restrict `HTMLInputElement::max_length` to the range of `i32`

Tim Ledbetter 7 月之前
父节点
当前提交
40d6b9d44e

+ 1 - 1
Libraries/LibWeb/HTML/HTMLInputElement.cpp

@@ -1832,7 +1832,7 @@ WebIDL::Long HTMLInputElement::max_length() const
 {
 {
     // The maxLength IDL attribute must reflect the maxlength content attribute, limited to only non-negative numbers.
     // The maxLength IDL attribute must reflect the maxlength content attribute, limited to only non-negative numbers.
     if (auto maxlength_string = get_attribute(HTML::AttributeNames::maxlength); maxlength_string.has_value()) {
     if (auto maxlength_string = get_attribute(HTML::AttributeNames::maxlength); maxlength_string.has_value()) {
-        if (auto maxlength = parse_non_negative_integer(*maxlength_string); maxlength.has_value())
+        if (auto maxlength = parse_non_negative_integer(*maxlength_string); maxlength.has_value() && *maxlength <= 2147483647)
             return *maxlength;
             return *maxlength;
     }
     }
     return -1;
     return -1;

+ 18 - 0
Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt

@@ -98,6 +98,24 @@ img.getAttribute("width") after img.setAttribute("width", "4294967295"): 4294967
 img.width after img.setAttribute("width", "4294967295"): 0
 img.width after img.setAttribute("width", "4294967295"): 0
 img.getAttribute("width") after img.width = 4294967295: 0
 img.getAttribute("width") after img.width = 4294967295: 0
 img.width after img.width = 4294967295: 0
 img.width after img.width = 4294967295: 0
+input.getAttribute("maxlength") after input.setAttribute("maxLength", "0"): 0
+input.maxLength after input.setAttribute("maxlength", "0"): 0
+input.getAttribute("maxlength") after input.maxLength = 0: 0
+input.maxLength after input.maxLength = 0: 0
+input.getAttribute("maxlength") after input.setAttribute("maxLength", "1"): 1
+input.maxLength after input.setAttribute("maxlength", "1"): 1
+input.getAttribute("maxlength") after input.maxLength = 1: 1
+input.maxLength after input.maxLength = 1: 1
+input.getAttribute("maxlength") after input.setAttribute("maxLength", "2147483647"): 2147483647
+input.maxLength after input.setAttribute("maxlength", "2147483647"): 2147483647
+input.getAttribute("maxlength") after input.maxLength = 2147483647: 2147483647
+input.maxLength after input.maxLength = 2147483647: 2147483647
+input.getAttribute("maxlength") after input.setAttribute("maxLength", "2147483648"): 2147483648
+input.maxLength after input.setAttribute("maxlength", "2147483648"): -1
+input.maxLength = 2147483648 threw exception of type IndexSizeError
+input.getAttribute("maxlength") after input.setAttribute("maxLength", "4294967295"): 4294967295
+input.maxLength after input.setAttribute("maxlength", "4294967295"): -1
+input.maxLength = 4294967295 threw exception of type IndexSizeError
 input.getAttribute("size") after input.setAttribute("size", "0"): 0
 input.getAttribute("size") after input.setAttribute("size", "0"): 0
 input.size after input.setAttribute("size", "0"): 20
 input.size after input.setAttribute("size", "0"): 20
 input.size = 0 threw exception of type IndexSizeError
 input.size = 0 threw exception of type IndexSizeError

+ 1 - 0
Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html

@@ -47,6 +47,7 @@
         testProperty("img", "height", (img) => img.height, (img, value) => img.height = value);
         testProperty("img", "height", (img) => img.height, (img, value) => img.height = value);
         testProperty("img", "hspace", (img) => img.hspace, (img, value) => img.hspace = value);
         testProperty("img", "hspace", (img) => img.hspace, (img, value) => img.hspace = value);
         testProperty("img", "width", (img) => img.width, (img, value) => img.width = value);
         testProperty("img", "width", (img) => img.width, (img, value) => img.width = value);
+        testProperty("input", "maxLength", (input) => input.maxLength, (input, value) => input.maxLength = value);
         testProperty("input", "size", (input) => input.size, (input, value) => input.size = value);
         testProperty("input", "size", (input) => input.size, (input, value) => input.size = value);
         testProperty(imageButtonInputFactory, "height", (input) => input.height, (input, value) => input.height = value);
         testProperty(imageButtonInputFactory, "height", (input) => input.height, (input, value) => input.height = value);
         testProperty(imageButtonInputFactory, "width", (input) => input.width, (input, value) => input.width = value);
         testProperty(imageButtonInputFactory, "width", (input) => input.width, (input, value) => input.width = value);