- Revision
- 135495
- Author
- [email protected]
- Date
- 2012-11-22 01:37:06 -0800 (Thu, 22 Nov 2012)
Log Message
HTML integer parsing functions don't natively handle 8 bit strings
https://bugs.webkit.org/show_bug.cgi?id=102997
Reviewed by Filip Pizlo.
Source/WebCore:
In order to avoid unnecessary up convering of 8 bit strings to 16 bits, added 8 bit paths to
parseHTMLInteger() and parseHTMLNonNegativeInteger() by breaking out the core logic into
templated helper functions. These methods are primarily used to process attribute values.
No new tests needed, functionnality covered by existing tests.
* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseHTMLIntegerInternal):
(WebCore::parseHTMLInteger):
(WebCore::parseHTMLNonNegativeIntegerInternal):
(WebCore::parseHTMLNonNegativeInteger):
Source/WTF:
Added exports to the LChar* versions of charactersToIntStrict() and charactersToUIntStrict()
to support the changes made to parseHTMLInteger() and parseHTMLNonNegativeInteger().
* wtf/text/WTFString.h:
(WTF::charactersToIntStrict): Added export
(WTF::charactersToUIntStrict): Added export
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (135494 => 135495)
--- trunk/Source/WTF/ChangeLog 2012-11-22 09:28:38 UTC (rev 135494)
+++ trunk/Source/WTF/ChangeLog 2012-11-22 09:37:06 UTC (rev 135495)
@@ -1,3 +1,17 @@
+2012-11-22 Michael Saboff <[email protected]>
+
+ HTML integer parsing functions don't natively handle 8 bit strings
+ https://bugs.webkit.org/show_bug.cgi?id=102997
+
+ Reviewed by Filip Pizlo.
+
+ Added exports to the LChar* versions of charactersToIntStrict() and charactersToUIntStrict()
+ to support the changes made to parseHTMLInteger() and parseHTMLNonNegativeInteger().
+
+ * wtf/text/WTFString.h:
+ (WTF::charactersToIntStrict): Added export
+ (WTF::charactersToUIntStrict): Added export
+
2012-11-21 Filip Pizlo <[email protected]>
Rename dataLog() and dataLogV() to dataLogF() and dataLogFV()
Modified: trunk/Source/WTF/wtf/text/WTFString.h (135494 => 135495)
--- trunk/Source/WTF/wtf/text/WTFString.h 2012-11-22 09:28:38 UTC (rev 135494)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2012-11-22 09:37:06 UTC (rev 135495)
@@ -58,9 +58,9 @@
// Declarations of string operations
-int charactersToIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
+WTF_EXPORT_STRING_API int charactersToIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
WTF_EXPORT_STRING_API int charactersToIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
-unsigned charactersToUIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
+WTF_EXPORT_STRING_API unsigned charactersToUIntStrict(const LChar*, size_t, bool* ok = 0, int base = 10);
WTF_EXPORT_STRING_API unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = 0, int base = 10);
int64_t charactersToInt64Strict(const LChar*, size_t, bool* ok = 0, int base = 10);
int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = 0, int base = 10);
Modified: trunk/Source/WebCore/ChangeLog (135494 => 135495)
--- trunk/Source/WebCore/ChangeLog 2012-11-22 09:28:38 UTC (rev 135494)
+++ trunk/Source/WebCore/ChangeLog 2012-11-22 09:37:06 UTC (rev 135495)
@@ -1,3 +1,22 @@
+2012-11-22 Michael Saboff <[email protected]>
+
+ HTML integer parsing functions don't natively handle 8 bit strings
+ https://bugs.webkit.org/show_bug.cgi?id=102997
+
+ Reviewed by Filip Pizlo.
+
+ In order to avoid unnecessary up convering of 8 bit strings to 16 bits, added 8 bit paths to
+ parseHTMLInteger() and parseHTMLNonNegativeInteger() by breaking out the core logic into
+ templated helper functions. These methods are primarily used to process attribute values.
+
+ No new tests needed, functionnality covered by existing tests.
+
+ * html/parser/HTMLParserIdioms.cpp:
+ (WebCore::parseHTMLIntegerInternal):
+ (WebCore::parseHTMLInteger):
+ (WebCore::parseHTMLNonNegativeIntegerInternal):
+ (WebCore::parseHTMLNonNegativeInteger):
+
2012-11-22 Kentaro Hara <[email protected]>
[V8] WebCoreStringResourceBase should be located in V8StringResource.h
Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp (135494 => 135495)
--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp 2012-11-22 09:28:38 UTC (rev 135494)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp 2012-11-22 09:37:06 UTC (rev 135495)
@@ -150,14 +150,9 @@
return parseToDoubleForNumberType(string, std::numeric_limits<double>::quiet_NaN());
}
-// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
-bool parseHTMLInteger(const String& input, int& value)
+template <typename CharacterType>
+static bool parseHTMLIntegerInternal(const CharacterType* position, const CharacterType* end, int& value)
{
- // Step 1
- // Step 2
- const UChar* position = input.characters();
- const UChar* end = position + input.length();
-
// Step 3
int sign = 1;
@@ -197,18 +192,31 @@
// Step 9
bool ok;
- value = sign * charactersToIntStrict(digits.characters(), digits.length(), &ok);
+ if (digits.is8Bit())
+ value = sign * charactersToIntStrict(digits.characters8(), digits.length(), &ok);
+ else
+ value = sign * charactersToIntStrict(digits.characters16(), digits.length(), &ok);
return ok;
}
-// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
-bool parseHTMLNonNegativeInteger(const String& input, unsigned int& value)
+// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
+bool parseHTMLInteger(const String& input, int& value)
{
// Step 1
// Step 2
- const UChar* position = input.characters();
- const UChar* end = position + input.length();
+ unsigned length = input.length();
+ if (length && input.is8Bit()) {
+ const LChar* start = input.characters8();
+ return parseHTMLIntegerInternal(start, start + length, value);
+ }
+ const UChar* start = input.characters();
+ return parseHTMLIntegerInternal(start, start + length, value);
+}
+
+template <typename CharacterType>
+static bool parseHTMLNonNegativeIntegerInternal(const CharacterType* position, const CharacterType* end, unsigned& value)
+{
// Step 3
while (position < end) {
if (!isHTMLSpace(*position))
@@ -244,8 +252,27 @@
// Step 9
bool ok;
- value = charactersToUIntStrict(digits.characters(), digits.length(), &ok);
+ if (digits.is8Bit())
+ value = charactersToUIntStrict(digits.characters8(), digits.length(), &ok);
+ else
+ value = charactersToUIntStrict(digits.characters16(), digits.length(), &ok);
return ok;
}
+
+// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
+bool parseHTMLNonNegativeInteger(const String& input, unsigned& value)
+{
+ // Step 1
+ // Step 2
+ unsigned length = input.length();
+ if (length && input.is8Bit()) {
+ const LChar* start = input.characters8();
+ return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
+ }
+
+ const UChar* start = input.characters();
+ return parseHTMLNonNegativeIntegerInternal(start, start + length, value);
}
+
+}