From bc484258c2923667a7b0d0330b64c2c616079915 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 30 Nov 2024 20:06:38 +0000 Subject: [PATCH] LibWeb: Restrict `HTMLInputElement::min_length` to the range of `i32` --- Libraries/LibWeb/HTML/HTMLInputElement.cpp | 2 +- .../expected/HTML/unsigned-long-reflection.txt | 18 ++++++++++++++++++ .../input/HTML/unsigned-long-reflection.html | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index e128fc6597d..64fc622507a 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1849,7 +1849,7 @@ WebIDL::Long HTMLInputElement::min_length() const { // The minLength IDL attribute must reflect the minlength content attribute, limited to only non-negative numbers. if (auto minlength_string = get_attribute(HTML::AttributeNames::minlength); minlength_string.has_value()) { - if (auto minlength = parse_non_negative_integer(*minlength_string); minlength.has_value()) + if (auto minlength = parse_non_negative_integer(*minlength_string); minlength.has_value() && *minlength <= 2147483647) return *minlength; } return -1; diff --git a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt index 45af9d98d35..dfea1e6a243 100644 --- a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt +++ b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt @@ -116,6 +116,24 @@ 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("minlength") after input.setAttribute("minLength", "0"): 0 +input.minLength after input.setAttribute("minlength", "0"): 0 +input.getAttribute("minlength") after input.minLength = 0: 0 +input.minLength after input.minLength = 0: 0 +input.getAttribute("minlength") after input.setAttribute("minLength", "1"): 1 +input.minLength after input.setAttribute("minlength", "1"): 1 +input.getAttribute("minlength") after input.minLength = 1: 1 +input.minLength after input.minLength = 1: 1 +input.getAttribute("minlength") after input.setAttribute("minLength", "2147483647"): 2147483647 +input.minLength after input.setAttribute("minlength", "2147483647"): 2147483647 +input.getAttribute("minlength") after input.minLength = 2147483647: 2147483647 +input.minLength after input.minLength = 2147483647: 2147483647 +input.getAttribute("minlength") after input.setAttribute("minLength", "2147483648"): 2147483648 +input.minLength after input.setAttribute("minlength", "2147483648"): -1 +input.minLength = 2147483648 threw exception of type IndexSizeError +input.getAttribute("minlength") after input.setAttribute("minLength", "4294967295"): 4294967295 +input.minLength after input.setAttribute("minlength", "4294967295"): -1 +input.minLength = 4294967295 threw exception of type IndexSizeError input.getAttribute("size") after input.setAttribute("size", "0"): 0 input.size after input.setAttribute("size", "0"): 20 input.size = 0 threw exception of type IndexSizeError diff --git a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html index 73b8b68655a..824f5c5b5c3 100644 --- a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html +++ b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html @@ -48,6 +48,7 @@ testProperty("img", "hspace", (img) => img.hspace, (img, value) => img.hspace = 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", "minLength", (input) => input.minLength, (input, value) => input.minLength = 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, "width", (input) => input.width, (input, value) => input.width = value);