Title: [103222] trunk
Revision
103222
Author
[email protected]
Date
2011-12-19 00:11:24 -0800 (Mon, 19 Dec 2011)

Log Message

Add support for 8 bits strings to Document::isValidName()
https://bugs.webkit.org/show_bug.cgi?id=74784

Patch by Benjamin Poulain <[email protected]> on 2011-12-19
Reviewed by Darin Adler.

Source/WebCore:

Avoid the conversion to 16bits when we are in the ASCII fast path,
otherwise fallback to the Unicode testing in 16bits.

* dom/Document.cpp:
(WebCore::isValidNameASCII):
(WebCore::Document::isValidName):

LayoutTests:

Add tests for valid and invalid names for nodes.

* fast/dom/Document/createElement-invalid-names-expected.txt: Added.
* fast/dom/Document/createElement-invalid-names.html: Added.
* fast/dom/Document/createElement-valid-names-expected.txt: Added.
* fast/dom/Document/createElement-valid-names.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (103221 => 103222)


--- trunk/LayoutTests/ChangeLog	2011-12-19 07:15:58 UTC (rev 103221)
+++ trunk/LayoutTests/ChangeLog	2011-12-19 08:11:24 UTC (rev 103222)
@@ -1,3 +1,17 @@
+2011-12-19  Benjamin Poulain  <[email protected]>
+
+        Add support for 8 bits strings to Document::isValidName()
+        https://bugs.webkit.org/show_bug.cgi?id=74784
+
+        Reviewed by Darin Adler.
+
+        Add tests for valid and invalid names for nodes.
+
+        * fast/dom/Document/createElement-invalid-names-expected.txt: Added.
+        * fast/dom/Document/createElement-invalid-names.html: Added.
+        * fast/dom/Document/createElement-valid-names-expected.txt: Added.
+        * fast/dom/Document/createElement-valid-names.html: Added.
+
 2011-12-18  Shinya Kawanaka  <[email protected]>
 
         A test that mutation happens when asynchronous spell checking is in process.

Added: trunk/LayoutTests/fast/dom/Document/createElement-invalid-names-expected.txt (0 => 103222)


--- trunk/LayoutTests/fast/dom/Document/createElement-invalid-names-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/createElement-invalid-names-expected.txt	2011-12-19 08:11:24 UTC (rev 103222)
@@ -0,0 +1,21 @@
+Test various valid name for elements according to the definition of DOM Level 2.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.createElement('0ascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('.Ascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('-Ascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement(' ascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('	ascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('֑sc.ii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('⃣scii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('िascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('ʳascii') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('asc i') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('asc	i') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS document.createElement('asciiⅦ') threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Document/createElement-invalid-names.html (0 => 103222)


--- trunk/LayoutTests/fast/dom/Document/createElement-invalid-names.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/createElement-invalid-names.html	2011-12-19 08:11:24 UTC (rev 103222)
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<script src=""
+</head>
+<body>
+<script>
+description("Test various valid name for elements according to the definition of DOM Level 2.")
+
+var nameList = [
+                // Invalid first Char
+                '0ascii',
+                '.Ascii',
+                '-Ascii',
+                ' ascii',
+                '	ascii',
+                '֑sc.ii',
+                '⃣scii',
+                'िascii',
+                'ʳascii',
+                // Invalid other char
+                'asc i',
+                'asc	i',
+                'asciiⅦ'
+                ];
+
+for (var i in nameList)
+    shouldThrow("document.createElement('" + nameList[i] +"')", "'Error: INVALID_CHARACTER_ERR: DOM Exception 5'");
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/Document/createElement-valid-names-expected.txt (0 => 103222)


--- trunk/LayoutTests/fast/dom/Document/createElement-valid-names-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/createElement-valid-names-expected.txt	2011-12-19 08:11:24 UTC (rev 103222)
@@ -0,0 +1,36 @@
+Test various valid name for elements according to the definition of DOM Level 2.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.createElement('ascii') is non-null.
+PASS document.createElement('Ascii') is non-null.
+PASS document.createElement('àscii') is non-null.
+PASS document.createElement('Àscii') is non-null.
+PASS document.createElement('āscii') is non-null.
+PASS document.createElement('Ăscii') is non-null.
+PASS document.createElement('ƻscii') is non-null.
+PASS document.createElement('אscii') is non-null.
+PASS document.createElement('āscii') is non-null.
+PASS document.createElement('āscii') is non-null.
+PASS document.createElement(':ascii') is non-null.
+PASS document.createElement('_ascii') is non-null.
+PASS document.createElement('aàscii') is non-null.
+PASS document.createElement('aÀscii') is non-null.
+PASS document.createElement('aāscii') is non-null.
+PASS document.createElement('aĂscii') is non-null.
+PASS document.createElement('aƻscii') is non-null.
+PASS document.createElement('aאscii') is non-null.
+PASS document.createElement('aāscii') is non-null.
+PASS document.createElement('aāscii') is non-null.
+PASS document.createElement('aa֑') is non-null.
+PASS document.createElement('a⃣') is non-null.
+PASS document.createElement('aि') is non-null.
+PASS document.createElement('aʳ') is non-null.
+PASS document.createElement('a0') is non-null.
+PASS document.createElement('a---i') is non-null.
+PASS document.createElement('a...i') is non-null.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Document/createElement-valid-names.html (0 => 103222)


--- trunk/LayoutTests/fast/dom/Document/createElement-valid-names.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Document/createElement-valid-names.html	2011-12-19 08:11:24 UTC (rev 103222)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<script src=""
+</head>
+<body>
+<script>
+description("Test various valid name for elements according to the definition of DOM Level 2.")
+
+var nameList = [
+                // First Char ASCII in Unicode categories Ll, Lu
+                'ascii',
+                'Ascii',
+                // First Char Latin1 in Unicode categories Ll, Lu
+                'àscii',
+                'Àscii',
+                // First Char Unicode, above Latin1, in categories Ll, Lu, Lo, Lt
+                'āscii',
+                'Ăscii',
+                'ƻscii',
+                'אscii',
+                'āscii',
+                'āscii',
+                // Exceptions for first Char: ':' and '_'
+                ':ascii',
+                '_ascii',
+                // Other Char Latin1 in Unicode categories Ll, Lu
+                'aàscii',
+                'aÀscii',
+                // Other Char Unicode, above Latin1, in categories Ll, Lu, Lo, Lt
+                'aāscii',
+                'aĂscii',
+                'aƻscii',
+                'aאscii',
+                'aāscii',
+                'aāscii',
+                // Other Char Unicode in Mc, Me, Mn, Lm, or Nd
+                'aa֑',
+                'a⃣',
+                'aि',
+                'aʳ',
+                'a0',
+                // Exceptions for other Char: '-' and '.'
+                'a---i',
+                'a...i',
+                ];
+
+for (var i in nameList)
+    shouldBeNonNull("document.createElement('" + nameList[i] +"')");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (103221 => 103222)


--- trunk/Source/WebCore/ChangeLog	2011-12-19 07:15:58 UTC (rev 103221)
+++ trunk/Source/WebCore/ChangeLog	2011-12-19 08:11:24 UTC (rev 103222)
@@ -1,3 +1,17 @@
+2011-12-19  Benjamin Poulain  <[email protected]>
+
+        Add support for 8 bits strings to Document::isValidName()
+        https://bugs.webkit.org/show_bug.cgi?id=74784
+
+        Reviewed by Darin Adler.
+
+        Avoid the conversion to 16bits when we are in the ASCII fast path,
+        otherwise fallback to the Unicode testing in 16bits.
+
+        * dom/Document.cpp:
+        (WebCore::isValidNameASCII):
+        (WebCore::Document::isValidName):
+
 2011-12-18  Kentaro Hara  <[email protected]>
 
         REGRESSION(r101445): [JSC] Generated code for custom getters and setters

Modified: trunk/Source/WebCore/dom/Document.cpp (103221 => 103222)


--- trunk/Source/WebCore/dom/Document.cpp	2011-12-19 07:15:58 UTC (rev 103221)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-12-19 08:11:24 UTC (rev 103222)
@@ -3775,9 +3775,10 @@
     return true;
 }
 
-static inline bool isValidNameASCII(const UChar* characters, unsigned length)
+template<typename CharType>
+static inline bool isValidNameASCII(const CharType* characters, unsigned length)
 {
-    UChar c = characters[0];
+    CharType c = characters[0];
     if (!(isASCIIAlpha(c) || c == ':' || c == '_'))
         return false;
 
@@ -3796,8 +3797,17 @@
     if (!length)
         return false;
 
-    const UChar* characters = name.characters();
-    return isValidNameASCII(characters, length) || isValidNameNonASCII(characters, length);
+    const UChar* characters;
+    if (name.is8Bit()) {
+        if (isValidNameASCII(name.characters8(), length))
+            return true;
+        characters = name.characters();
+    } else {
+        characters = name.characters16();
+        if (isValidNameASCII(characters, length))
+            return true;
+    }
+    return isValidNameNonASCII(characters, length);
 }
 
 bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, String& localName, ExceptionCode& ec)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to