Title: [217864] trunk
Revision
217864
Author
[email protected]
Date
2017-06-06 15:38:27 -0700 (Tue, 06 Jun 2017)

Log Message

Update to slightly stricter rules for custom element names from more recent standard draft
https://bugs.webkit.org/show_bug.cgi?id=173019

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/interfaces-expected.txt: Expect more PASS.

Source/WebCore:

* bindings/js/JSCustomElementRegistryCustom.cpp:
(WebCore::validateCustomElementNameAndThrowIfNeeded): Add more error strings for various error cases.

* dom/Document.cpp:
(WebCore::isPotentialCustomElementNameCharacter): Added. Implements the PCENChar production
from the standard by listing all the ranges exactly as they appear in the standard.
(WebCore::Document::validateCustomElementName): Added a check that the first character is
a lowercase ASCII letter. Added a check that all characters are potential custom element
name characters.

* dom/Document.h: Update the CustomElementNameValidationStatus with new values for
the various new error cases.  Not sure that validateCustomElementName really belongs
in the Document class in the first place. Also seems that the error strings could be
in validateCustomElementName rather than in a separate bindings function, obviating
the need for the enum.

LayoutTests:

* platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt: Expect more PASS.
* platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt: Ditto.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (217863 => 217864)


--- trunk/LayoutTests/ChangeLog	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/LayoutTests/ChangeLog	2017-06-06 22:38:27 UTC (rev 217864)
@@ -1,3 +1,13 @@
+2017-06-06  Darin Adler  <[email protected]>
+
+        Update to slightly stricter rules for custom element names from more recent standard draft
+        https://bugs.webkit.org/show_bug.cgi?id=173019
+
+        Reviewed by Ryosuke Niwa.
+
+        * platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt: Expect more PASS.
+        * platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt: Ditto.
+
 2017-06-06  Yoav Weiss  <[email protected]>
 
         [preload] Conditional support for media preloading and align media `as` values.

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (217863 => 217864)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-06-06 22:38:27 UTC (rev 217864)
@@ -1,3 +1,12 @@
+2017-06-06  Darin Adler  <[email protected]>
+
+        Update to slightly stricter rules for custom element names from more recent standard draft
+        https://bugs.webkit.org/show_bug.cgi?id=173019
+
+        Reviewed by Ryosuke Niwa.
+
+        * web-platform-tests/html/semantics/interfaces-expected.txt: Expect more PASS.
+
 2017-06-04  Chris Dumez  <[email protected]>
 
         Implement DOMMatrixReadOnly.transformPoint()

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt (217863 => 217864)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt	2017-06-06 22:38:27 UTC (rev 217864)
@@ -292,6 +292,6 @@
 PASS Interfaces for WBR 
 PASS Interfaces for xmp 
 PASS Interfaces for XMP 
-FAIL Interfaces for å-bar assert_equals: Element å-bar should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
-FAIL Interfaces for Å-BAR assert_equals: Element Å-BAR should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
+PASS Interfaces for å-bar 
+PASS Interfaces for Å-BAR 
 

Modified: trunk/LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt (217863 => 217864)


--- trunk/LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt	2017-06-06 22:38:27 UTC (rev 217864)
@@ -292,6 +292,6 @@
 PASS Interfaces for WBR 
 PASS Interfaces for xmp 
 PASS Interfaces for XMP 
-FAIL Interfaces for å-bar assert_equals: Element å-bar should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
-FAIL Interfaces for Å-BAR assert_equals: Element Å-BAR should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
+PASS Interfaces for å-bar 
+PASS Interfaces for Å-BAR 
 

Modified: trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt (217863 => 217864)


--- trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt	2017-06-06 22:38:27 UTC (rev 217864)
@@ -292,6 +292,6 @@
 PASS Interfaces for WBR 
 PASS Interfaces for xmp 
 PASS Interfaces for XMP 
-FAIL Interfaces for å-bar assert_equals: Element å-bar should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
-FAIL Interfaces for Å-BAR assert_equals: Element Å-BAR should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
+PASS Interfaces for å-bar 
+PASS Interfaces for Å-BAR 
 

Modified: trunk/Source/WebCore/ChangeLog (217863 => 217864)


--- trunk/Source/WebCore/ChangeLog	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/Source/WebCore/ChangeLog	2017-06-06 22:38:27 UTC (rev 217864)
@@ -1,3 +1,26 @@
+2017-06-06  Darin Adler  <[email protected]>
+
+        Update to slightly stricter rules for custom element names from more recent standard draft
+        https://bugs.webkit.org/show_bug.cgi?id=173019
+
+        Reviewed by Ryosuke Niwa.
+
+        * bindings/js/JSCustomElementRegistryCustom.cpp:
+        (WebCore::validateCustomElementNameAndThrowIfNeeded): Add more error strings for various error cases.
+
+        * dom/Document.cpp:
+        (WebCore::isPotentialCustomElementNameCharacter): Added. Implements the PCENChar production
+        from the standard by listing all the ranges exactly as they appear in the standard.
+        (WebCore::Document::validateCustomElementName): Added a check that the first character is
+        a lowercase ASCII letter. Added a check that all characters are potential custom element
+        name characters.
+
+        * dom/Document.h: Update the CustomElementNameValidationStatus with new values for
+        the various new error cases.  Not sure that validateCustomElementName really belongs
+        in the Document class in the first place. Also seems that the error strings could be
+        in validateCustomElementName rather than in a separate bindings function, obviating
+        the need for the enum.
+
 2017-06-06  Yoav Weiss  <[email protected]>
 
         [preload] Conditional support for media preloading and align media `as` values.

Modified: trunk/Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp (217863 => 217864)


--- trunk/Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp	2017-06-06 22:38:27 UTC (rev 217864)
@@ -57,19 +57,24 @@
 static bool validateCustomElementNameAndThrowIfNeeded(ExecState& state, const AtomicString& name)
 {
     auto scope = DECLARE_THROW_SCOPE(state.vm());
-
     switch (Document::validateCustomElementName(name)) {
     case CustomElementNameValidationStatus::Valid:
         return true;
-    case CustomElementNameValidationStatus::ConflictsWithBuiltinNames:
-        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot be same as one of the builtin elements"));
+    case CustomElementNameValidationStatus::FirstCharacterIsNotLowercaseASCIILetter:
+        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name must have a lowercase ASCII letter as its first character"));
         return false;
-    case CustomElementNameValidationStatus::NoHyphen:
+    case CustomElementNameValidationStatus::ContainsUppercaseASCIILetter:
+        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot contain an uppercase ASCII letter"));
+        return false;
+    case CustomElementNameValidationStatus::ContainsNoHyphen:
         throwSyntaxError(&state, scope, ASCIILiteral("Custom element name must contain a hyphen"));
         return false;
-    case CustomElementNameValidationStatus::ContainsUpperCase:
-        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot contain an upper case letter"));
+    case CustomElementNameValidationStatus::ContainsDisallowedCharacter:
+        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name contains a character that is not allowed"));
         return false;
+    case CustomElementNameValidationStatus::ConflictsWithStandardElementName:
+        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot be same as one of the standard elements"));
+        return false;
     }
     ASSERT_NOT_REACHED();
     return false;

Modified: trunk/Source/WebCore/dom/Document.cpp (217863 => 217864)


--- trunk/Source/WebCore/dom/Document.cpp	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/Source/WebCore/dom/Document.cpp	2017-06-06 22:38:27 UTC (rev 217864)
@@ -1062,18 +1062,79 @@
     return element.releaseNonNull();
 }
 
+// https://html.spec.whatwg.org/#valid-custom-element-name
+
+struct UnicodeCodePointRange {
+    UChar32 minimum;
+    UChar32 maximum;
+};
+
+#if !ASSERT_DISABLED
+
+static inline bool operator<(const UnicodeCodePointRange& a, const UnicodeCodePointRange& b)
+{
+    ASSERT(a.minimum <= a.maximum);
+    ASSERT(b.minimum <= b.maximum);
+    return a.maximum < b.minimum;
+}
+
+#endif
+
+static inline bool operator<(const UnicodeCodePointRange& a, UChar32 b)
+{
+    ASSERT(a.minimum <= a.maximum);
+    return a.maximum < b;
+}
+
+static inline bool operator<(UChar32 a, const UnicodeCodePointRange& b)
+{
+    ASSERT(b.minimum <= b.maximum);
+    return a < b.minimum;
+}
+
+static inline bool isPotentialCustomElementNameCharacter(UChar32 character)
+{
+    static const UnicodeCodePointRange ranges[] = {
+        { '-', '.' },
+        { '0', '9' },
+        { '_', '_' },
+        { 'a', 'z' },
+        { 0xB7, 0xB7 },
+        { 0xC0, 0xD6 },
+        { 0xD8, 0xF6 },
+        { 0xF8, 0x37D },
+        { 0x37F, 0x1FFF },
+        { 0x200C, 0x200D },
+        { 0x203F, 0x2040 },
+        { 0x2070, 0x218F },
+        { 0x2C00, 0x2FEF },
+        { 0x3001, 0xD7FF },
+        { 0xF900, 0xFDCF },
+        { 0xFDF0, 0xFFFD },
+        { 0x10000, 0xEFFFF },
+    };
+
+    ASSERT(std::is_sorted(std::begin(ranges), std::end(ranges)));
+    return std::binary_search(std::begin(ranges), std::end(ranges), character);
+}
+
 CustomElementNameValidationStatus Document::validateCustomElementName(const AtomicString& localName)
 {
+    if (!isASCIILower(localName[0]))
+        return CustomElementNameValidationStatus::FirstCharacterIsNotLowercaseASCIILetter;
+
     bool containsHyphen = false;
-    for (auto character : StringView(localName).codeUnits()) {
+    for (auto character : StringView(localName).codePoints()) {
         if (isASCIIUpper(character))
-            return CustomElementNameValidationStatus::ContainsUpperCase;
+            return CustomElementNameValidationStatus::ContainsUppercaseASCIILetter;
+        if (!isPotentialCustomElementNameCharacter(character))
+            return CustomElementNameValidationStatus::ContainsDisallowedCharacter;
         if (character == '-')
             containsHyphen = true;
     }
 
     if (!containsHyphen)
-        return CustomElementNameValidationStatus::NoHyphen;
+        return CustomElementNameValidationStatus::ContainsNoHyphen;
 
 #if ENABLE(MATHML)
     const auto& annotationXmlLocalName = MathMLNames::annotation_xmlTag.localName();
@@ -1089,7 +1150,7 @@
         || localName == SVGNames::font_face_uriTag.localName()
         || localName == SVGNames::missing_glyphTag.localName()
         || localName == annotationXmlLocalName)
-        return CustomElementNameValidationStatus::ConflictsWithBuiltinNames;
+        return CustomElementNameValidationStatus::ConflictsWithStandardElementName;
 
     return CustomElementNameValidationStatus::Valid;
 }

Modified: trunk/Source/WebCore/dom/Document.h (217863 => 217864)


--- trunk/Source/WebCore/dom/Document.h	2017-06-06 22:36:27 UTC (rev 217863)
+++ trunk/Source/WebCore/dom/Document.h	2017-06-06 22:38:27 UTC (rev 217864)
@@ -275,7 +275,14 @@
     DisabledByContentDispositionAttachmentSandbox
 };
 
-enum class CustomElementNameValidationStatus { Valid, ConflictsWithBuiltinNames, NoHyphen, ContainsUpperCase };
+enum class CustomElementNameValidationStatus {
+    Valid,
+    FirstCharacterIsNotLowercaseASCIILetter,
+    ContainsNoHyphen,
+    ContainsUppercaseASCIILetter,
+    ContainsDisallowedCharacter,
+    ConflictsWithStandardElementName
+};
 
 class Document
     : public ContainerNode
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to