Title: [133625] trunk/Source/WebCore
- Revision
- 133625
- Author
- [email protected]
- Date
- 2012-11-06 09:42:03 -0800 (Tue, 06 Nov 2012)
Log Message
quoteCSSString() always creates a 16 bit string
https://bugs.webkit.org/show_bug.cgi?id=101004
Reviewed by Darin Adler.
Added a new templated helper based on character type from the logic of quoteCSSString() to process
the argument string based on its native bitness.
Functionality covered by existing tests.
* css/CSSParser.cpp:
(WebCore::quoteCSSStringInternal):
(WebCore::quoteCSSString):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (133624 => 133625)
--- trunk/Source/WebCore/ChangeLog 2012-11-06 17:34:48 UTC (rev 133624)
+++ trunk/Source/WebCore/ChangeLog 2012-11-06 17:42:03 UTC (rev 133625)
@@ -1,3 +1,19 @@
+2012-11-06 Michael Saboff <[email protected]>
+
+ quoteCSSString() always creates a 16 bit string
+ https://bugs.webkit.org/show_bug.cgi?id=101004
+
+ Reviewed by Darin Adler.
+
+ Added a new templated helper based on character type from the logic of quoteCSSString() to process
+ the argument string based on its native bitness.
+
+ Functionality covered by existing tests.
+
+ * css/CSSParser.cpp:
+ (WebCore::quoteCSSStringInternal):
+ (WebCore::quoteCSSString):
+
2012-11-06 Andras Becsi <[email protected]>
[Qt][WK2] Fit-to-width broken on pages with viewport meta tag
Modified: trunk/Source/WebCore/css/CSSParser.cpp (133624 => 133625)
--- trunk/Source/WebCore/css/CSSParser.cpp 2012-11-06 17:34:48 UTC (rev 133624)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2012-11-06 17:42:03 UTC (rev 133625)
@@ -10871,20 +10871,16 @@
return isCSSTokenizerURL(string.characters(), length);
}
-// We use single quotes for now because markup.cpp uses double quotes.
-String quoteCSSString(const String& string)
+
+template <typename CharacterType>
+static inline String quoteCSSStringInternal(const CharacterType* characters, unsigned length)
{
- // This function expands each character to at most 3 characters ('\u0010' -> '\' '1' '0') as well as adds
- // 2 quote characters (before and after). Make sure the resulting size (3 * length + 2) will not overflow unsigned.
- if (string.length() >= (std::numeric_limits<unsigned>::max() / 3) - 2)
- return "";
-
// For efficiency, we first pre-calculate the length of the quoted string, then we build the actual one.
// Please see below for the actual logic.
unsigned quotedStringSize = 2; // Two quotes surrounding the entire string.
bool afterEscape = false;
- for (unsigned i = 0; i < string.length(); ++i) {
- UChar ch = string[i];
+ for (unsigned i = 0; i < length; ++i) {
+ CharacterType ch = characters[i];
if (ch == '\\' || ch == '\'') {
quotedStringSize += 2;
afterEscape = false;
@@ -10897,12 +10893,12 @@
}
}
- StringBuffer<UChar> buffer(quotedStringSize);
+ StringBuffer<CharacterType> buffer(quotedStringSize);
unsigned index = 0;
buffer[index++] = '\'';
afterEscape = false;
- for (unsigned i = 0; i < string.length(); ++i) {
- UChar ch = string[i];
+ for (unsigned i = 0; i < length; ++i) {
+ CharacterType ch = characters[i];
if (ch == '\\' || ch == '\'') {
buffer[index++] = '\\';
buffer[index++] = ch;
@@ -10925,6 +10921,25 @@
return String::adopt(buffer);
}
+// We use single quotes for now because markup.cpp uses double quotes.
+String quoteCSSString(const String& string)
+{
+ // This function expands each character to at most 3 characters ('\u0010' -> '\' '1' '0') as well as adds
+ // 2 quote characters (before and after). Make sure the resulting size (3 * length + 2) will not overflow unsigned.
+
+ unsigned length = string.length();
+
+ if (!length)
+ return String("\'\'");
+
+ if (length > std::numeric_limits<unsigned>::max() / 3 - 2)
+ return emptyString();
+
+ if (string.is8Bit())
+ return quoteCSSStringInternal(string.characters8(), length);
+ return quoteCSSStringInternal(string.characters16(), length);
+}
+
String quoteCSSStringIfNeeded(const String& string)
{
return isCSSTokenizerIdentifier(string) ? string : quoteCSSString(string);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes