Changeset 217864 in webkit


Ignore:
Timestamp:
Jun 6, 2017 3:38:27 PM (7 years ago)
Author:
Darin Adler
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.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r217863 r217864  
     12017-06-06  Darin Adler  <darin@apple.com>
     2
     3        Update to slightly stricter rules for custom element names from more recent standard draft
     4        https://bugs.webkit.org/show_bug.cgi?id=173019
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt: Expect more PASS.
     9        * platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt: Ditto.
     10
    1112017-06-06  Yoav Weiss  <yoav@yoav.ws>
    212
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r217767 r217864  
     12017-06-06  Darin Adler  <darin@apple.com>
     2
     3        Update to slightly stricter rules for custom element names from more recent standard draft
     4        https://bugs.webkit.org/show_bug.cgi?id=173019
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * web-platform-tests/html/semantics/interfaces-expected.txt: Expect more PASS.
     9
    1102017-06-04  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt

    r210823 r217864  
    293293PASS Interfaces for xmp
    294294PASS Interfaces for XMP
    295 FAIL Interfaces for å-bar assert_equals: Element å-bar should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
    296 FAIL Interfaces for Å-BAR assert_equals: Element Å-BAR should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
     295PASS Interfaces for å-bar
     296PASS Interfaces for Å-BAR
    297297
  • trunk/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt

    r210823 r217864  
    293293PASS Interfaces for xmp
    294294PASS Interfaces for XMP
    295 FAIL Interfaces for å-bar assert_equals: Element å-bar should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
    296 FAIL Interfaces for Å-BAR assert_equals: Element Å-BAR should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
     295PASS Interfaces for å-bar
     296PASS Interfaces for Å-BAR
    297297
  • trunk/LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/interfaces-expected.txt

    r205579 r217864  
    293293PASS Interfaces for xmp
    294294PASS Interfaces for XMP
    295 FAIL Interfaces for å-bar assert_equals: Element å-bar should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
    296 FAIL Interfaces for Å-BAR assert_equals: Element Å-BAR should have HTMLUnknownElement as its primary interface. expected "[object HTMLUnknownElement]" but got "[object HTMLElement]"
     295PASS Interfaces for å-bar
     296PASS Interfaces for Å-BAR
    297297
  • trunk/Source/WebCore/ChangeLog

    r217863 r217864  
     12017-06-06  Darin Adler  <darin@apple.com>
     2
     3        Update to slightly stricter rules for custom element names from more recent standard draft
     4        https://bugs.webkit.org/show_bug.cgi?id=173019
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * bindings/js/JSCustomElementRegistryCustom.cpp:
     9        (WebCore::validateCustomElementNameAndThrowIfNeeded): Add more error strings for various error cases.
     10
     11        * dom/Document.cpp:
     12        (WebCore::isPotentialCustomElementNameCharacter): Added. Implements the PCENChar production
     13        from the standard by listing all the ranges exactly as they appear in the standard.
     14        (WebCore::Document::validateCustomElementName): Added a check that the first character is
     15        a lowercase ASCII letter. Added a check that all characters are potential custom element
     16        name characters.
     17
     18        * dom/Document.h: Update the CustomElementNameValidationStatus with new values for
     19        the various new error cases.  Not sure that validateCustomElementName really belongs
     20        in the Document class in the first place. Also seems that the error strings could be
     21        in validateCustomElementName rather than in a separate bindings function, obviating
     22        the need for the enum.
     23
    1242017-06-06  Yoav Weiss  <yoav@yoav.ws>
    225
  • trunk/Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp

    r216501 r217864  
    5858{
    5959    auto scope = DECLARE_THROW_SCOPE(state.vm());
    60 
    6160    switch (Document::validateCustomElementName(name)) {
    6261    case CustomElementNameValidationStatus::Valid:
    6362        return true;
    64     case CustomElementNameValidationStatus::ConflictsWithBuiltinNames:
    65         throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot be same as one of the builtin elements"));
    66         return false;
    67     case CustomElementNameValidationStatus::NoHyphen:
     63    case CustomElementNameValidationStatus::FirstCharacterIsNotLowercaseASCIILetter:
     64        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name must have a lowercase ASCII letter as its first character"));
     65        return false;
     66    case CustomElementNameValidationStatus::ContainsUppercaseASCIILetter:
     67        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot contain an uppercase ASCII letter"));
     68        return false;
     69    case CustomElementNameValidationStatus::ContainsNoHyphen:
    6870        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name must contain a hyphen"));
    6971        return false;
    70     case CustomElementNameValidationStatus::ContainsUpperCase:
    71         throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot contain an upper case letter"));
     72    case CustomElementNameValidationStatus::ContainsDisallowedCharacter:
     73        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name contains a character that is not allowed"));
     74        return false;
     75    case CustomElementNameValidationStatus::ConflictsWithStandardElementName:
     76        throwSyntaxError(&state, scope, ASCIILiteral("Custom element name cannot be same as one of the standard elements"));
    7277        return false;
    7378    }
  • trunk/Source/WebCore/dom/Document.cpp

    r217860 r217864  
    10631063}
    10641064
     1065// https://html.spec.whatwg.org/#valid-custom-element-name
     1066
     1067struct UnicodeCodePointRange {
     1068    UChar32 minimum;
     1069    UChar32 maximum;
     1070};
     1071
     1072#if !ASSERT_DISABLED
     1073
     1074static inline bool operator<(const UnicodeCodePointRange& a, const UnicodeCodePointRange& b)
     1075{
     1076    ASSERT(a.minimum <= a.maximum);
     1077    ASSERT(b.minimum <= b.maximum);
     1078    return a.maximum < b.minimum;
     1079}
     1080
     1081#endif
     1082
     1083static inline bool operator<(const UnicodeCodePointRange& a, UChar32 b)
     1084{
     1085    ASSERT(a.minimum <= a.maximum);
     1086    return a.maximum < b;
     1087}
     1088
     1089static inline bool operator<(UChar32 a, const UnicodeCodePointRange& b)
     1090{
     1091    ASSERT(b.minimum <= b.maximum);
     1092    return a < b.minimum;
     1093}
     1094
     1095static inline bool isPotentialCustomElementNameCharacter(UChar32 character)
     1096{
     1097    static const UnicodeCodePointRange ranges[] = {
     1098        { '-', '.' },
     1099        { '0', '9' },
     1100        { '_', '_' },
     1101        { 'a', 'z' },
     1102        { 0xB7, 0xB7 },
     1103        { 0xC0, 0xD6 },
     1104        { 0xD8, 0xF6 },
     1105        { 0xF8, 0x37D },
     1106        { 0x37F, 0x1FFF },
     1107        { 0x200C, 0x200D },
     1108        { 0x203F, 0x2040 },
     1109        { 0x2070, 0x218F },
     1110        { 0x2C00, 0x2FEF },
     1111        { 0x3001, 0xD7FF },
     1112        { 0xF900, 0xFDCF },
     1113        { 0xFDF0, 0xFFFD },
     1114        { 0x10000, 0xEFFFF },
     1115    };
     1116
     1117    ASSERT(std::is_sorted(std::begin(ranges), std::end(ranges)));
     1118    return std::binary_search(std::begin(ranges), std::end(ranges), character);
     1119}
     1120
    10651121CustomElementNameValidationStatus Document::validateCustomElementName(const AtomicString& localName)
    10661122{
     1123    if (!isASCIILower(localName[0]))
     1124        return CustomElementNameValidationStatus::FirstCharacterIsNotLowercaseASCIILetter;
     1125
    10671126    bool containsHyphen = false;
    1068     for (auto character : StringView(localName).codeUnits()) {
     1127    for (auto character : StringView(localName).codePoints()) {
    10691128        if (isASCIIUpper(character))
    1070             return CustomElementNameValidationStatus::ContainsUpperCase;
     1129            return CustomElementNameValidationStatus::ContainsUppercaseASCIILetter;
     1130        if (!isPotentialCustomElementNameCharacter(character))
     1131            return CustomElementNameValidationStatus::ContainsDisallowedCharacter;
    10711132        if (character == '-')
    10721133            containsHyphen = true;
     
    10741135
    10751136    if (!containsHyphen)
    1076         return CustomElementNameValidationStatus::NoHyphen;
     1137        return CustomElementNameValidationStatus::ContainsNoHyphen;
    10771138
    10781139#if ENABLE(MATHML)
     
    10901151        || localName == SVGNames::missing_glyphTag.localName()
    10911152        || localName == annotationXmlLocalName)
    1092         return CustomElementNameValidationStatus::ConflictsWithBuiltinNames;
     1153        return CustomElementNameValidationStatus::ConflictsWithStandardElementName;
    10931154
    10941155    return CustomElementNameValidationStatus::Valid;
  • trunk/Source/WebCore/dom/Document.h

    r217734 r217864  
    276276};
    277277
    278 enum class CustomElementNameValidationStatus { Valid, ConflictsWithBuiltinNames, NoHyphen, ContainsUpperCase };
     278enum class CustomElementNameValidationStatus {
     279    Valid,
     280    FirstCharacterIsNotLowercaseASCIILetter,
     281    ContainsNoHyphen,
     282    ContainsUppercaseASCIILetter,
     283    ContainsDisallowedCharacter,
     284    ConflictsWithStandardElementName
     285};
    279286
    280287class Document
Note: See TracChangeset for help on using the changeset viewer.