Ver código fonte

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

Tim Ledbetter 7 meses atrás
pai
commit
ac7fad52f6

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

@@ -259,7 +259,7 @@ WebIDL::Long HTMLTextAreaElement::max_length() const
 {
     // 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 = 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 -1;

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

@@ -253,6 +253,24 @@ select.getAttribute("size") after select.setAttribute("size", "4294967295"): 429
 select.size after select.setAttribute("size", "4294967295"): 0
 select.getAttribute("size") after select.size = 4294967295: 0
 select.size after select.size = 4294967295: 0
+textarea.getAttribute("minlength") after textarea.setAttribute("minLength", "0"): 0
+textarea.minLength after textarea.setAttribute("minlength", "0"): 0
+textarea.getAttribute("minlength") after textarea.minLength = 0: 0
+textarea.minLength after textarea.minLength = 0: 0
+textarea.getAttribute("minlength") after textarea.setAttribute("minLength", "1"): 1
+textarea.minLength after textarea.setAttribute("minlength", "1"): 1
+textarea.getAttribute("minlength") after textarea.minLength = 1: 1
+textarea.minLength after textarea.minLength = 1: 1
+textarea.getAttribute("minlength") after textarea.setAttribute("minLength", "2147483647"): 2147483647
+textarea.minLength after textarea.setAttribute("minlength", "2147483647"): 2147483647
+textarea.getAttribute("minlength") after textarea.minLength = 2147483647: 2147483647
+textarea.minLength after textarea.minLength = 2147483647: 2147483647
+textarea.getAttribute("minlength") after textarea.setAttribute("minLength", "2147483648"): 2147483648
+textarea.minLength after textarea.setAttribute("minlength", "2147483648"): -2147483648
+textarea.minLength = 2147483648 threw exception of type IndexSizeError
+textarea.getAttribute("minlength") after textarea.setAttribute("minLength", "4294967295"): 4294967295
+textarea.minLength after textarea.setAttribute("minlength", "4294967295"): -1
+textarea.minLength = 4294967295 threw exception of type IndexSizeError
 textarea.getAttribute("rows") after textarea.setAttribute("rows", "0"): 0
 textarea.rows after textarea.setAttribute("rows", "0"): 2
 textarea.getAttribute("rows") after textarea.rows = 0: 2

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

@@ -55,6 +55,7 @@
         testProperty("marquee", "scrollAmount", (marquee) => marquee.scrollAmount, (marquee, value) => marquee.scrollAmount = value);
         testProperty("marquee", "scrollDelay", (marquee) => marquee.scrollDelay, (marquee, value) => marquee.scrollDelay = value);
         testProperty("select", "size", (select) => select.size, (select, value) => select.size = value);
+        testProperty("textarea", "minLength", (textarea) => textarea.minLength, (textarea, value) => textarea.minLength = value);
         testProperty("textarea", "rows", (textarea) => textarea.rows, (textarea, value) => textarea.rows = value);
         testProperty("textarea", "cols", (textarea) => textarea.cols, (textarea, value) => textarea.cols = value);
     });