Add support for 8 bits strings to Document::isValidName()
https://bugs.webkit.org/show_bug.cgi?id=74784
Patch by Benjamin Poulain <bpoulain@apple.com> 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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@103222 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/dom/Document/createElement-invalid-names-expected.txt b/LayoutTests/fast/dom/Document/createElement-invalid-names-expected.txt
new file mode 100644
index 0000000..ba47482
--- /dev/null
+++ b/LayoutTests/fast/dom/Document/createElement-invalid-names-expected.txt
@@ -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
+
diff --git a/LayoutTests/fast/dom/Document/createElement-invalid-names.html b/LayoutTests/fast/dom/Document/createElement-invalid-names.html
new file mode 100644
index 0000000..0879df7
--- /dev/null
+++ b/LayoutTests/fast/dom/Document/createElement-invalid-names.html
@@ -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="../../js/resources/js-test-pre.js"></script>
+</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="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/Document/createElement-valid-names-expected.txt b/LayoutTests/fast/dom/Document/createElement-valid-names-expected.txt
new file mode 100644
index 0000000..040f932
--- /dev/null
+++ b/LayoutTests/fast/dom/Document/createElement-valid-names-expected.txt
@@ -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
+
diff --git a/LayoutTests/fast/dom/Document/createElement-valid-names.html b/LayoutTests/fast/dom/Document/createElement-valid-names.html
new file mode 100644
index 0000000..20833eb
--- /dev/null
+++ b/LayoutTests/fast/dom/Document/createElement-valid-names.html
@@ -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="../../js/resources/js-test-pre.js"></script>
+</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="../../js/resources/js-test-post.js"></script>
+</body>
+</html>