Title: [208674] trunk
Revision
208674
Author
[email protected]
Date
2016-11-13 23:06:52 -0800 (Sun, 13 Nov 2016)

Log Message

REGRESSION (204441): newsplex.com map does not load
https://bugs.webkit.org/show_bug.cgi?id=164705
<rdar://problem/28753438>

Reviewed by Darin Adler.

Source/WebCore:

Update getElementsByTagName(qualifiedName) implementation to match more closely
the specification at:
- https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
- https://dom.spec.whatwg.org/#concept-getelementsbytagname
- https://dom.spec.whatwg.org/#concept-element-qualified-name

In particular, we no longer split the input qualifiedName into a prefix and a
localName in order to compare those to element.prefix() / element.localName().
Instead, we keep the input qualifiedName as is and compare it to the element's
qualifiedName. This matters for HTML elements inside an HTML document that have
a semicolon in their localname (e.g. 'wx:map'). For this example, the element's
localName and its qualified name are both 'wx:map'. Calling
getElementsByTagName('wx:map') should return it. However, if you split the input
qualifiedName into a prefix and a localName, you end up checking:
'wx' == null && 'map' == 'wx:map'
which does not match.

Test: fast/dom/getElementsByTagName-HTMLElement-prefix.html

* dom/TagCollection.cpp:
(WebCore::TagCollection::TagCollection):
(WebCore::TagCollection::~TagCollection):
(WebCore::HTMLTagCollection::HTMLTagCollection):
(WebCore::HTMLTagCollection::~HTMLTagCollection):
(WebCore::makeQualifiedName): Deleted.
(WebCore::splitQualifiedName): Deleted.
* dom/TagCollection.h:
(WebCore::TagCollection::elementMatches):
(WebCore::HTMLTagCollection::elementMatches):

LayoutTests:

* fast/dom/getElementsByTagName-HTMLElement-prefix-expected.txt: Added.
* fast/dom/getElementsByTagName-HTMLElement-prefix.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (208673 => 208674)


--- trunk/LayoutTests/ChangeLog	2016-11-14 05:14:07 UTC (rev 208673)
+++ trunk/LayoutTests/ChangeLog	2016-11-14 07:06:52 UTC (rev 208674)
@@ -1,3 +1,14 @@
+2016-11-13  Chris Dumez  <[email protected]>
+
+        REGRESSION (204441): newsplex.com map does not load
+        https://bugs.webkit.org/show_bug.cgi?id=164705
+        <rdar://problem/28753438>
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/getElementsByTagName-HTMLElement-prefix-expected.txt: Added.
+        * fast/dom/getElementsByTagName-HTMLElement-prefix.html: Added.
+
 2016-11-12  Simon Fraser  <[email protected]>
 
         Add a way to get the UI-side scrolling tree as text via UIScriptController

Added: trunk/LayoutTests/fast/dom/getElementsByTagName-HTMLElement-prefix-expected.txt (0 => 208674)


--- trunk/LayoutTests/fast/dom/getElementsByTagName-HTMLElement-prefix-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/getElementsByTagName-HTMLElement-prefix-expected.txt	2016-11-14 07:06:52 UTC (rev 208674)
@@ -0,0 +1,18 @@
+Tests that getElementsByTagName() works properly for elements that have a semicolon in their tag name, inside an HTML document.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testElement.prefix is null
+PASS testElement.localName is "wx:map"
+PASS testElement.tagName is "WX:MAP"
+collection = document.getElementsByTagName("wx:map")
+PASS collection.length is 1
+PASS collection[0] is testElement
+collection = document.getElementsByTagName("WX:MAP")
+PASS collection.length is 1
+PASS collection[0] is testElement
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/getElementsByTagName-HTMLElement-prefix.html (0 => 208674)


--- trunk/LayoutTests/fast/dom/getElementsByTagName-HTMLElement-prefix.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/getElementsByTagName-HTMLElement-prefix.html	2016-11-14 07:06:52 UTC (rev 208674)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<wx:map id="testElement"></wx:map>
+<script>
+description("Tests that getElementsByTagName() works properly for elements that have a semicolon in their tag name, inside an HTML document.");
+
+var testElement = document.getElementById("testElement");
+shouldBeNull("testElement.prefix");
+shouldBeEqualToString("testElement.localName", "wx:map");
+shouldBeEqualToString("testElement.tagName", "WX:MAP");
+
+evalAndLog('collection = document.getElementsByTagName("wx:map")');
+shouldBe("collection.length", "1");
+shouldBe("collection[0]", "testElement");
+
+evalAndLog('collection = document.getElementsByTagName("WX:MAP")');
+shouldBe("collection.length", "1");
+shouldBe("collection[0]", "testElement");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (208673 => 208674)


--- trunk/Source/WebCore/ChangeLog	2016-11-14 05:14:07 UTC (rev 208673)
+++ trunk/Source/WebCore/ChangeLog	2016-11-14 07:06:52 UTC (rev 208674)
@@ -1,3 +1,41 @@
+2016-11-13  Chris Dumez  <[email protected]>
+
+        REGRESSION (204441): newsplex.com map does not load
+        https://bugs.webkit.org/show_bug.cgi?id=164705
+        <rdar://problem/28753438>
+
+        Reviewed by Darin Adler.
+
+        Update getElementsByTagName(qualifiedName) implementation to match more closely
+        the specification at:
+        - https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
+        - https://dom.spec.whatwg.org/#concept-getelementsbytagname
+        - https://dom.spec.whatwg.org/#concept-element-qualified-name
+
+        In particular, we no longer split the input qualifiedName into a prefix and a
+        localName in order to compare those to element.prefix() / element.localName().
+        Instead, we keep the input qualifiedName as is and compare it to the element's
+        qualifiedName. This matters for HTML elements inside an HTML document that have
+        a semicolon in their localname (e.g. 'wx:map'). For this example, the element's
+        localName and its qualified name are both 'wx:map'. Calling
+        getElementsByTagName('wx:map') should return it. However, if you split the input
+        qualifiedName into a prefix and a localName, you end up checking:
+        'wx' == null && 'map' == 'wx:map'
+        which does not match.
+
+        Test: fast/dom/getElementsByTagName-HTMLElement-prefix.html
+
+        * dom/TagCollection.cpp:
+        (WebCore::TagCollection::TagCollection):
+        (WebCore::TagCollection::~TagCollection):
+        (WebCore::HTMLTagCollection::HTMLTagCollection):
+        (WebCore::HTMLTagCollection::~HTMLTagCollection):
+        (WebCore::makeQualifiedName): Deleted.
+        (WebCore::splitQualifiedName): Deleted.
+        * dom/TagCollection.h:
+        (WebCore::TagCollection::elementMatches):
+        (WebCore::HTMLTagCollection::elementMatches):
+
 2016-11-13  Darin Adler  <[email protected]>
 
         Remove ExceptionCodePlaceholder

Modified: trunk/Source/WebCore/dom/TagCollection.cpp (208673 => 208674)


--- trunk/Source/WebCore/dom/TagCollection.cpp	2016-11-14 05:14:07 UTC (rev 208673)
+++ trunk/Source/WebCore/dom/TagCollection.cpp	2016-11-14 07:06:52 UTC (rev 208674)
@@ -28,25 +28,6 @@
 
 namespace WebCore {
 
-static inline AtomicString makeQualifiedName(const String& prefix, const String& localName)
-{
-    if (LIKELY(prefix.isNull()))
-        return localName;
-    return prefix + ':' + localName;
-}
-
-static inline void splitQualifiedName(const String& qualifiedName, AtomicString& prefix, AtomicString& localName)
-{
-    size_t index = qualifiedName.find(':');
-    if (UNLIKELY(index == notFound))
-        localName = qualifiedName;
-    else {
-        prefix = qualifiedName.substring(0, index);
-        localName = qualifiedName.substring(index + 1);
-    }
-    ASSERT(makeQualifiedName(prefix, localName) == qualifiedName);
-}
-
 TagCollectionNS::TagCollectionNS(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
     : CachedHTMLCollection<TagCollectionNS, CollectionTypeTraits<ByTag>::traversalType>(rootNode, ByTag)
     , m_namespaceURI(namespaceURI)
@@ -62,28 +43,27 @@
 
 TagCollection::TagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName)
     : CachedHTMLCollection<TagCollection, CollectionTypeTraits<ByTag>::traversalType>(rootNode, ByTag)
+    , m_qualifiedName(qualifiedName)
 {
     ASSERT(qualifiedName != starAtom);
-    splitQualifiedName(qualifiedName, m_prefix, m_localName);
 }
 
 TagCollection::~TagCollection()
 {
-    ownerNode().nodeLists()->removeCachedCollection(this, makeQualifiedName(m_prefix, m_localName));
+    ownerNode().nodeLists()->removeCachedCollection(this, m_qualifiedName);
 }
 
 HTMLTagCollection::HTMLTagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName)
     : CachedHTMLCollection<HTMLTagCollection, CollectionTypeTraits<ByHTMLTag>::traversalType>(rootNode, ByHTMLTag)
+    , m_qualifiedName(qualifiedName)
+    , m_loweredQualifiedName(qualifiedName.convertToASCIILowercase())
 {
     ASSERT(qualifiedName != starAtom);
-    splitQualifiedName(qualifiedName, m_prefix, m_localName);
-    m_loweredPrefix = m_prefix.convertToASCIILowercase();
-    m_loweredLocalName = m_localName.convertToASCIILowercase();
 }
 
 HTMLTagCollection::~HTMLTagCollection()
 {
-    ownerNode().nodeLists()->removeCachedCollection(this, makeQualifiedName(m_prefix, m_localName));
+    ownerNode().nodeLists()->removeCachedCollection(this, m_qualifiedName);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/TagCollection.h (208673 => 208674)


--- trunk/Source/WebCore/dom/TagCollection.h	2016-11-14 05:14:07 UTC (rev 208673)
+++ trunk/Source/WebCore/dom/TagCollection.h	2016-11-14 07:06:52 UTC (rev 208674)
@@ -43,8 +43,7 @@
 private:
     TagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName);
 
-    AtomicString m_prefix;
-    AtomicString m_localName;
+    AtomicString m_qualifiedName;
 };
 
 class TagCollectionNS final : public CachedHTMLCollection<TagCollectionNS, CollectionTypeTraits<ByTag>::traversalType> {
@@ -78,15 +77,13 @@
 private:
     HTMLTagCollection(ContainerNode& rootNode, const AtomicString& qualifiedName);
 
-    AtomicString m_prefix;
-    AtomicString m_loweredPrefix;
-    AtomicString m_localName;
-    AtomicString m_loweredLocalName;
+    AtomicString m_qualifiedName;
+    AtomicString m_loweredQualifiedName;
 };
 
 inline bool TagCollection::elementMatches(Element& element) const
 {
-    return m_localName == element.localName() && m_prefix == element.prefix();
+    return m_qualifiedName == element.tagQName().toString();
 }
 
 inline bool TagCollectionNS::elementMatches(Element& element) const
@@ -99,8 +96,8 @@
 inline bool HTMLTagCollection::elementMatches(Element& element) const
 {
     if (element.isHTMLElement())
-        return m_loweredLocalName == element.localName() && m_loweredPrefix == element.prefix();
-    return m_localName == element.localName() && m_prefix == element.prefix();
+        return m_loweredQualifiedName == element.tagQName().toString();
+    return m_qualifiedName == element.tagQName().toString();
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to