Title: [205663] trunk/Source/WebCore
Revision
205663
Author
[email protected]
Date
2016-09-08 14:31:54 -0700 (Thu, 08 Sep 2016)

Log Message

Update parseHTMLNonNegativeInteger() to return an unsigned value
https://bugs.webkit.org/show_bug.cgi?id=161759

Reviewed by Alex Christensen.

Update parseHTMLNonNegativeInteger() to return an unsigned value instead
of a signed one as the value can never be negative.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::parseBorderWidthAttribute):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::width):
(WebCore::HTMLImageElement::height):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::maxLengthAttributeChanged):
(WebCore::HTMLInputElement::minLengthAttributeChanged):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::maxLengthAttributeChanged):
(WebCore::HTMLTextAreaElement::minLengthAttributeChanged):
* html/ImageInputType.cpp:
(WebCore::ImageInputType::height):
(WebCore::ImageInputType::width):
* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseHTMLNonNegativeInteger):
(WebCore::parseHTTPRefreshInternal):
* html/parser/HTMLParserIdioms.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205662 => 205663)


--- trunk/Source/WebCore/ChangeLog	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/ChangeLog	2016-09-08 21:31:54 UTC (rev 205663)
@@ -1,3 +1,32 @@
+2016-09-08  Chris Dumez  <[email protected]>
+
+        Update parseHTMLNonNegativeInteger() to return an unsigned value
+        https://bugs.webkit.org/show_bug.cgi?id=161759
+
+        Reviewed by Alex Christensen.
+
+        Update parseHTMLNonNegativeInteger() to return an unsigned value instead
+        of a signed one as the value can never be negative.
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::parseBorderWidthAttribute):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::width):
+        (WebCore::HTMLImageElement::height):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::maxLengthAttributeChanged):
+        (WebCore::HTMLInputElement::minLengthAttributeChanged):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged):
+        (WebCore::HTMLTextAreaElement::minLengthAttributeChanged):
+        * html/ImageInputType.cpp:
+        (WebCore::ImageInputType::height):
+        (WebCore::ImageInputType::width):
+        * html/parser/HTMLParserIdioms.cpp:
+        (WebCore::parseHTMLNonNegativeInteger):
+        (WebCore::parseHTTPRefreshInternal):
+        * html/parser/HTMLParserIdioms.h:
+
 2016-09-08  Said Abou-Hallawa  <[email protected]>
 
         Get rid of the color profile from ImageFrame and ImageDecoder

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (205662 => 205663)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2016-09-08 21:31:54 UTC (rev 205663)
@@ -102,7 +102,7 @@
 
 unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString& value) const
 {
-    if (Optional<int> borderWidth = parseHTMLNonNegativeInteger(value))
+    if (Optional<unsigned> borderWidth = parseHTMLNonNegativeInteger(value))
         return borderWidth.value();
 
     return hasTagName(tableTag) ? 1 : 0;

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (205662 => 205663)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2016-09-08 21:31:54 UTC (rev 205663)
@@ -380,7 +380,7 @@
 {
     if (!renderer()) {
         // check the attribute first for an explicit pixel value
-        Optional<int> width = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(widthAttr));
+        Optional<unsigned> width = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(widthAttr));
         if (width)
             return width.value();
 
@@ -405,7 +405,7 @@
 {
     if (!renderer()) {
         // check the attribute first for an explicit pixel value
-        Optional<int> height = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(heightAttr));
+        Optional<unsigned> height = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(heightAttr));
         if (height)
             return height.value();
 

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (205662 => 205663)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2016-09-08 21:31:54 UTC (rev 205663)
@@ -1785,7 +1785,11 @@
 void HTMLInputElement::maxLengthAttributeChanged(const AtomicString& newValue)
 {
     unsigned oldEffectiveMaxLength = effectiveMaxLength();
-    setMaxLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    if (Optional<unsigned> maxLength = parseHTMLNonNegativeInteger(newValue))
+        setMaxLength(maxLength.value());
+    else
+        setMaxLength(-1);
+
     if (oldEffectiveMaxLength != effectiveMaxLength())
         updateValueIfNeeded();
 
@@ -1797,7 +1801,11 @@
 void HTMLInputElement::minLengthAttributeChanged(const AtomicString& newValue)
 {
     int oldMinLength = minLength();
-    setMinLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    if (Optional<unsigned> minLength = parseHTMLNonNegativeInteger(newValue))
+        setMinLength(minLength.value());
+    else
+        setMinLength(-1);
+
     if (oldMinLength != minLength())
         updateValueIfNeeded();
 

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (205662 => 205663)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2016-09-08 21:31:54 UTC (rev 205663)
@@ -205,13 +205,21 @@
 
 void HTMLTextAreaElement::maxLengthAttributeChanged(const AtomicString& newValue)
 {
-    setMaxLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    if (Optional<unsigned> maxLength = parseHTMLNonNegativeInteger(newValue))
+        setMaxLength(maxLength.value());
+    else
+        setMaxLength(-1);
+
     updateValidity();
 }
 
 void HTMLTextAreaElement::minLengthAttributeChanged(const AtomicString& newValue)
 {
-    setMinLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
+    if (Optional<unsigned> minLength = parseHTMLNonNegativeInteger(newValue))
+        setMinLength(minLength.value());
+    else
+        setMinLength(-1);
+
     updateValidity();
 }
 

Modified: trunk/Source/WebCore/html/ImageInputType.cpp (205662 => 205663)


--- trunk/Source/WebCore/html/ImageInputType.cpp	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/ImageInputType.cpp	2016-09-08 21:31:54 UTC (rev 205663)
@@ -176,7 +176,7 @@
 
     if (!element->renderer()) {
         // Check the attribute first for an explicit pixel value.
-        if (Optional<int> height = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(heightAttr)))
+        if (Optional<unsigned> height = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(heightAttr)))
             return height.value();
 
         // If the image is available, use its height.
@@ -197,7 +197,7 @@
 
     if (!element->renderer()) {
         // Check the attribute first for an explicit pixel value.
-        if (Optional<int> width = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(widthAttr)))
+        if (Optional<unsigned> width = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(widthAttr)))
             return width.value();
 
         // If the image is available, use its width.

Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp (205662 => 205663)


--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp	2016-09-08 21:31:54 UTC (rev 205663)
@@ -207,13 +207,13 @@
 }
 
 // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-non-negative-integers
-Optional<int> parseHTMLNonNegativeInteger(const String& input)
+Optional<unsigned> parseHTMLNonNegativeInteger(const String& input)
 {
     Optional<int> signedValue = parseHTMLInteger(input);
     if (!signedValue || signedValue.value() < 0)
         return Nullopt;
 
-    return signedValue;
+    return static_cast<unsigned>(signedValue.value());
 }
 
 template <typename CharacterType>
@@ -363,7 +363,7 @@
     while (position < end && isASCIIDigit(*position))
         ++position;
 
-    Optional<int> number = parseHTMLNonNegativeInteger(StringView(numberStart, position - numberStart).toStringWithoutCopying());
+    Optional<unsigned> number = parseHTMLNonNegativeInteger(StringView(numberStart, position - numberStart).toStringWithoutCopying());
     if (!number)
         return false;
 

Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.h (205662 => 205663)


--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.h	2016-09-08 21:30:17 UTC (rev 205662)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.h	2016-09-08 21:31:54 UTC (rev 205663)
@@ -65,7 +65,7 @@
 WEBCORE_EXPORT Optional<int> parseHTMLInteger(const String&);
 
 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
-WEBCORE_EXPORT Optional<int> parseHTMLNonNegativeInteger(const String&);
+WEBCORE_EXPORT Optional<unsigned> parseHTMLNonNegativeInteger(const String&);
 
 // https://html.spec.whatwg.org/#valid-non-negative-integer
 Optional<int> parseValidHTMLNonNegativeInteger(StringView);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to