Ver código fonte

LibWeb: Don't allow `HTMLTextAreaElement` rows and cols to be set to 0

In this case we should fall back to the default value.
Tim Ledbetter 7 meses atrás
pai
commit
aafc829e6d

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

@@ -299,16 +299,16 @@ unsigned HTMLTextAreaElement::cols() const
     return 20;
 }
 
-WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_cols(unsigned cols)
+WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_cols(WebIDL::UnsignedLong cols)
 {
-    if (cols > 2147483647)
+    if (cols == 0 || cols > 2147483647)
         cols = 20;
 
     return set_attribute(HTML::AttributeNames::cols, String::number(cols));
 }
 
 // https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-rows
-unsigned HTMLTextAreaElement::rows() const
+WebIDL::UnsignedLong HTMLTextAreaElement::rows() const
 {
     // The cols and rows attributes are limited to only positive numbers with fallback. The rows IDL attribute's default value is 2.
     if (auto rows_string = get_attribute(HTML::AttributeNames::rows); rows_string.has_value()) {
@@ -318,9 +318,9 @@ unsigned HTMLTextAreaElement::rows() const
     return 2;
 }
 
-WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_rows(unsigned rows)
+WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_rows(WebIDL::UnsignedLong rows)
 {
-    if (rows > 2147483647)
+    if (rows == 0 || rows > 2147483647)
         rows = 2;
 
     return set_attribute(HTML::AttributeNames::rows, String::number(rows));

+ 3 - 3
Libraries/LibWeb/HTML/HTMLTextAreaElement.h

@@ -102,11 +102,11 @@ public:
     WebIDL::Long min_length() const;
     WebIDL::ExceptionOr<void> set_min_length(WebIDL::Long);
 
-    unsigned cols() const;
+    WebIDL::UnsignedLong cols() const;
     WebIDL::ExceptionOr<void> set_cols(unsigned);
 
-    unsigned rows() const;
-    WebIDL::ExceptionOr<void> set_rows(unsigned);
+    WebIDL::UnsignedLong rows() const;
+    WebIDL::ExceptionOr<void> set_rows(WebIDL::UnsignedLong);
 
     // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
     WebIDL::UnsignedLong selection_start_binding() const;

+ 24 - 1
Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt

@@ -1,3 +1,7 @@
+img.getAttribute("hspace") after img.setAttribute("hspace", "0"): 0
+img.hspace after img.setAttribute("hspace", "0"): 0
+img.getAttribute("hspace") after img.hspace = 0: 0
+img.hspace after img.hspace = 0: 0
 img.getAttribute("hspace") after img.setAttribute("hspace", "1"): 1
 img.hspace after img.setAttribute("hspace", "1"): 1
 img.getAttribute("hspace") after img.hspace = 1: 1
@@ -14,6 +18,9 @@ img.getAttribute("hspace") after img.setAttribute("hspace", "4294967295"): 42949
 img.hspace after img.setAttribute("hspace", "4294967295"): 0
 img.getAttribute("hspace") after img.hspace = 4294967295: 0
 img.hspace after img.hspace = 4294967295: 0
+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
 input.getAttribute("size") after input.setAttribute("size", "1"): 1
 input.size after input.setAttribute("size", "1"): 1
 input.getAttribute("size") after input.size = 1: 1
@@ -30,6 +37,10 @@ input.getAttribute("size") after input.setAttribute("size", "4294967295"): 42949
 input.size after input.setAttribute("size", "4294967295"): 20
 input.getAttribute("size") after input.size = 4294967295: 20
 input.size after input.size = 4294967295: 20
+marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount", "0"): 0
+marquee.scrollAmount after marquee.setAttribute("scrollamount", "0"): 0
+marquee.getAttribute("scrollamount") after marquee.scrollAmount = 0: 0
+marquee.scrollAmount after marquee.scrollAmount = 0: 0
 marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount", "1"): 1
 marquee.scrollAmount after marquee.setAttribute("scrollamount", "1"): 1
 marquee.getAttribute("scrollamount") after marquee.scrollAmount = 1: 1
@@ -46,6 +57,10 @@ marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount",
 marquee.scrollAmount after marquee.setAttribute("scrollamount", "4294967295"): 6
 marquee.getAttribute("scrollamount") after marquee.scrollAmount = 4294967295: 6
 marquee.scrollAmount after marquee.scrollAmount = 4294967295: 6
+marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "0"): 0
+marquee.scrollDelay after marquee.setAttribute("scrolldelay", "0"): 0
+marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 0: 0
+marquee.scrollDelay after marquee.scrollDelay = 0: 0
 marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "1"): 1
 marquee.scrollDelay after marquee.setAttribute("scrolldelay", "1"): 1
 marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 1: 1
@@ -62,6 +77,10 @@ marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "4
 marquee.scrollDelay after marquee.setAttribute("scrolldelay", "4294967295"): 85
 marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 4294967295: 85
 marquee.scrollDelay after marquee.scrollDelay = 4294967295: 85
+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
+textarea.rows after textarea.rows = 0: 2
 textarea.getAttribute("rows") after textarea.setAttribute("rows", "1"): 1
 textarea.rows after textarea.setAttribute("rows", "1"): 1
 textarea.getAttribute("rows") after textarea.rows = 1: 1
@@ -78,6 +97,10 @@ textarea.getAttribute("rows") after textarea.setAttribute("rows", "4294967295"):
 textarea.rows after textarea.setAttribute("rows", "4294967295"): 2
 textarea.getAttribute("rows") after textarea.rows = 4294967295: 2
 textarea.rows after textarea.rows = 4294967295: 2
+textarea.getAttribute("cols") after textarea.setAttribute("cols", "0"): 0
+textarea.cols after textarea.setAttribute("cols", "0"): 20
+textarea.getAttribute("cols") after textarea.cols = 0: 20
+textarea.cols after textarea.cols = 0: 20
 textarea.getAttribute("cols") after textarea.setAttribute("cols", "1"): 1
 textarea.cols after textarea.setAttribute("cols", "1"): 1
 textarea.getAttribute("cols") after textarea.cols = 1: 1
@@ -93,4 +116,4 @@ textarea.cols after textarea.cols = 2147483648: 20
 textarea.getAttribute("cols") after textarea.setAttribute("cols", "4294967295"): 4294967295
 textarea.cols after textarea.setAttribute("cols", "4294967295"): 20
 textarea.getAttribute("cols") after textarea.cols = 4294967295: 20
-textarea.cols after textarea.cols = 4294967295: 20
+textarea.cols after textarea.cols = 4294967295: 20

+ 8 - 3
Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html

@@ -11,11 +11,16 @@
                 println(`${elementName}.${propertyName} after ${elementName}.setAttribute("${attributeName}", "${value}"): ${propertyGetter(element)}`);
 
                 element = document.createElement(elementName);
-                propertySetter(element, value);
-                println(`${elementName}.getAttribute("${attributeName}") after ${elementName}.${propertyName} = ${value}: ${element.getAttribute(attributeName)}`);
-                println(`${elementName}.${propertyName} after ${elementName}.${propertyName} = ${value}: ${propertyGetter(element)}`);
+                try {
+                    propertySetter(element, value);
+                    println(`${elementName}.getAttribute("${attributeName}") after ${elementName}.${propertyName} = ${value}: ${element.getAttribute(attributeName)}`);
+                    println(`${elementName}.${propertyName} after ${elementName}.${propertyName} = ${value}: ${propertyGetter(element)}`);
+                } catch (e) {
+                    println(`${elementName}.${propertyName} = ${value} threw exception of type ${e.name}`);    
+                }
             }
 
+            setValue(0);
             setValue(1);
             setValue(2147483647);
             setValue(2147483648);