Changeset 124210 in webkit


Ignore:
Timestamp:
Jul 31, 2012, 9:02:14 AM (13 years ago)
Author:
schenney@chromium.org
Message:

xmlserializer strips xlink from xlink:html svg image tag
https://bugs.webkit.org/show_bug.cgi?id=79586

Reviewed by Nikolas Zimmermann.

Source/WebCore:

Adding code to ensure the correct prefix on attributes in the xml,
xmlns and xlink namespaces. We now follow the rules in
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#serializing-html-fragments
(circa the time of this change).

Rob Buis wrote the original test for this patch and did the initial work.

Tests: fast/dom/XMLSerializer-xml-namespace.html

svg/custom/xlink-prefix-in-attributes.html

  • editing/MarkupAccumulator.cpp:

(WebCore::attributeIsInSerializedNamespace): Test for an attribute in
a specially serialized namespace: xml, xmlns, xlink.
(WebCore):
(WebCore::MarkupAccumulator::appendAttribute): Check the namespace of
attributes upon serialization, and add any necessary prefixes.

  • html/parser/HTMLTreeBuilder.cpp:

(WebCore::adjustForeignAttributes): Use WTF::xmlAtom etc for AtomicString arguments.

Source/WTF:

Add WTF::xlinkAtom as a global AtomicString constant.

  • wtf/text/AtomicString.h:

(WTF): Add xlinkAtom.

  • wtf/text/StringStatics.cpp:

(WTF): Add xlinkAtom.
(WTF::AtomicString::init): Add xlinkAtom.

LayoutTests:

Adding code to ensure the correct prefix on attributes in the xml,
xmlns and xlink namespaces. We now follow the rules in
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#serializing-html-fragments
(circa the time of this change).

Rob Buis wrote the original test for this patch and did the initial work.

  • editing/pasteboard/paste-noscript-svg-expected.txt: Updated.
  • fast/dom/XMLSerializer-xml-namespace-expected.txt: Added.
  • fast/dom/XMLSerializer-xml-namespace.html: Added. Tests serializing attributes with the xml namespace.
  • svg/custom/xlink-prefix-in-attributes-expected.txt: Added.
  • svg/custom/xlink-prefix-in-attributes.html: Added. Tests serializing attributes in the xmlns and xlink namespaces.
Location:
trunk
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r124209 r124210  
     12012-07-31  Stephen Chenney  <schenney@chromium.org>
     2
     3        xmlserializer strips xlink from xlink:html svg image tag
     4        https://bugs.webkit.org/show_bug.cgi?id=79586
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        Adding code to ensure the correct prefix on attributes in the xml,
     9        xmlns and xlink namespaces. We now follow the rules in
     10        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#serializing-html-fragments
     11        (circa the time of this change).
     12
     13        Rob Buis wrote the original test for this patch and did the initial work.
     14
     15
     16        * editing/pasteboard/paste-noscript-svg-expected.txt: Updated.
     17        * fast/dom/XMLSerializer-xml-namespace-expected.txt: Added.
     18        * fast/dom/XMLSerializer-xml-namespace.html: Added. Tests serializing attributes with the xml namespace.
     19        * svg/custom/xlink-prefix-in-attributes-expected.txt: Added.
     20        * svg/custom/xlink-prefix-in-attributes.html: Added. Tests serializing attributes in the xmlns and xlink namespaces.
     21
    1222012-07-31  Mike Reed  <reed@google.com>
    223
  • trunk/LayoutTests/editing/pasteboard/paste-noscript-svg-expected.txt

    r79625 r124210  
    22Hello
    33world
    4 <div id="div1">Hello</div><svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="5cm" height="3cm" viewBox="0 0 5 3" version="1.1"><a href=""><ellipse cx="2.5" cy="1.5" rx="2" ry="1" fill="red"></ellipse></a></svg><div id="div2">world</div>
     4<div id="div1">Hello</div><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="5cm" height="3cm" viewBox="0 0 5 3" version="1.1"><a xlink:href=""><ellipse cx="2.5" cy="1.5" rx="2" ry="1" fill="red"></ellipse></a></svg><div id="div2">world</div>
    55
  • trunk/Source/WTF/ChangeLog

    r124134 r124210  
     12012-07-31  Stephen Chenney  <schenney@chromium.org>
     2
     3        xmlserializer strips xlink from xlink:html svg image tag
     4        https://bugs.webkit.org/show_bug.cgi?id=79586
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        Add WTF::xlinkAtom as a global AtomicString constant.
     9
     10        * wtf/text/AtomicString.h:
     11        (WTF): Add xlinkAtom.
     12        * wtf/text/StringStatics.cpp:
     13        (WTF): Add xlinkAtom.
     14        (WTF::AtomicString::init): Add xlinkAtom.
     15
    1162012-07-30  Patrick Gansterer  <paroga@webkit.org>
    217
  • trunk/Source/WTF/wtf/text/AtomicString.h

    r124069 r124210  
    211211extern const WTF_EXPORTDATA AtomicString xmlAtom;
    212212extern const WTF_EXPORTDATA AtomicString xmlnsAtom;
     213extern const WTF_EXPORTDATA AtomicString xlinkAtom;
    213214
    214215inline AtomicString AtomicString::fromUTF8(const char* characters, size_t length)
     
    248249using WTF::xmlAtom;
    249250using WTF::xmlnsAtom;
     251using WTF::xlinkAtom;
    250252#endif
    251253
  • trunk/Source/WTF/wtf/text/StringStatics.cpp

    r111778 r124210  
    6060WTF_EXPORTDATA DEFINE_GLOBAL(AtomicString, xmlAtom, "xml")
    6161WTF_EXPORTDATA DEFINE_GLOBAL(AtomicString, xmlnsAtom, "xmlns")
     62WTF_EXPORTDATA DEFINE_GLOBAL(AtomicString, xlinkAtom, "xlink")
    6263
    6364NEVER_INLINE unsigned StringImpl::hashSlowCase() const
     
    8586        new (NotNull, (void*)&xmlAtom) AtomicString("xml");
    8687        new (NotNull, (void*)&xmlnsAtom) AtomicString("xmlns");
     88        new (NotNull, (void*)&xlinkAtom) AtomicString("xlink");
    8789
    8890        initialized = true;
  • trunk/Source/WebCore/ChangeLog

    r124209 r124210  
     12012-07-31  Stephen Chenney  <schenney@chromium.org>
     2
     3        xmlserializer strips xlink from xlink:html svg image tag
     4        https://bugs.webkit.org/show_bug.cgi?id=79586
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        Adding code to ensure the correct prefix on attributes in the xml,
     9        xmlns and xlink namespaces. We now follow the rules in
     10        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#serializing-html-fragments
     11        (circa the time of this change).
     12
     13        Rob Buis wrote the original test for this patch and did the initial work.
     14
     15        Tests: fast/dom/XMLSerializer-xml-namespace.html
     16               svg/custom/xlink-prefix-in-attributes.html
     17
     18        * editing/MarkupAccumulator.cpp:
     19        (WebCore::attributeIsInSerializedNamespace): Test for an attribute in
     20        a specially serialized namespace: xml, xmlns, xlink.
     21        (WebCore):
     22        (WebCore::MarkupAccumulator::appendAttribute): Check the namespace of
     23        attributes upon serialization, and add any necessary prefixes.
     24        * html/parser/HTMLTreeBuilder.cpp:
     25        (WebCore::adjustForeignAttributes): Use WTF::xmlAtom etc for AtomicString arguments.
     26
    1272012-07-31  Mike Reed  <reed@google.com>
    228
  • trunk/Source/WebCore/editing/MarkupAccumulator.cpp

    r116685 r124210  
    3737#include "KURL.h"
    3838#include "ProcessingInstruction.h"
     39#include "XLinkNames.h"
    3940#include "XMLNSNames.h"
     41#include "XMLNames.h"
    4042#include <wtf/unicode/CharacterNames.h>
    4143
     
    419421}
    420422
     423static inline bool attributeIsInSerializedNamespace(const Attribute& attribute)
     424{
     425    return attribute.namespaceURI() == XMLNames::xmlNamespaceURI
     426        || attribute.namespaceURI() == XLinkNames::xlinkNamespaceURI
     427        || attribute.namespaceURI() == XMLNSNames::xmlnsNamespaceURI;
     428}
     429
    421430void MarkupAccumulator::appendAttribute(StringBuilder& result, Element* element, const Attribute& attribute, Namespaces* namespaces)
    422431{
     
    425434    result.append(' ');
    426435
    427     if (documentIsHTML)
     436    if (documentIsHTML && !attributeIsInSerializedNamespace(attribute))
    428437        result.append(attribute.name().localName());
    429     else
    430         result.append(attribute.name().toString());
     438    else {
     439        QualifiedName prefixedName = attribute.name();
     440        if (attribute.namespaceURI() == XLinkNames::xlinkNamespaceURI) {
     441            if (attribute.prefix() != xlinkAtom)
     442                prefixedName.setPrefix(xlinkAtom);
     443        } else if (attribute.namespaceURI() == XMLNames::xmlNamespaceURI) {
     444            if (attribute.prefix() != xmlAtom)
     445                prefixedName.setPrefix(xmlAtom);
     446        } else if (attribute.namespaceURI() == XMLNSNames::xmlnsNamespaceURI) {
     447            if (attribute.name() != XMLNSNames::xmlnsAttr && attribute.prefix() != xmlnsAtom)
     448                prefixedName.setPrefix(xmlnsAtom);
     449        }
     450        result.append(prefixedName.toString());
     451    }
    431452
    432453    result.append('=');
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r123804 r124210  
    711711    if (!map) {
    712712        map = new PrefixedNameToQualifiedNameMap;
     713
    713714        QualifiedName** attrs = XLinkNames::getXLinkAttrs();
    714         addNamesWithPrefix(map, "xlink", attrs, XLinkNames::XLinkAttrsCount);
     715        addNamesWithPrefix(map, xlinkAtom, attrs, XLinkNames::XLinkAttrsCount);
    715716
    716717        attrs = XMLNames::getXMLAttrs();
    717         addNamesWithPrefix(map, "xml", attrs, XMLNames::XMLAttrsCount);
    718 
    719         map->add("xmlns", XMLNSNames::xmlnsAttr);
    720         map->add("xmlns:xlink", QualifiedName("xmlns", "xlink", XMLNSNames::xmlnsNamespaceURI));
     718        addNamesWithPrefix(map, xmlAtom, attrs, XMLNames::XMLAttrsCount);
     719
     720        map->add(WTF::xmlnsAtom, XMLNSNames::xmlnsAttr);
     721        map->add("xmlns:xlink", QualifiedName(xmlnsAtom, xlinkAtom, XMLNSNames::xmlnsNamespaceURI));
    721722    }
    722723
Note: See TracChangeset for help on using the changeset viewer.