Reviewed by Mitz.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Dec 2006 08:34:00 +0000 (08:34 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Dec 2006 08:34:00 +0000 (08:34 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=11998
        Incorrect serialization of quotation marks in XML attributes.

        Test: fast/dom/serialize-attribute.xhtml

        * editing/markup.cpp:
        (WebCore::escapeTextForMarkup): Added an isAttributeValue parameter, as the quotation mark
        only needs to be encoded in attribute values.
        (WebCore::startMarkup): Pass appropriate isAttributeValue to escapeTextForMarkup().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18484 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/serialize-attribute-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/serialize-attribute.xhtml [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/markup.cpp

index 3872b1d..cae20b8 100644 (file)
@@ -1,3 +1,13 @@
+2006-12-30  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Mitz.
+
+        Test for http://bugs.webkit.org/show_bug.cgi?id=11998
+        Incorrect serialization of quotation marks in XML attributes.
+
+        * fast/dom/serialize-attribute-expected.txt: Added.
+        * fast/dom/serialize-attribute.xhtml: Added.
+
 2006-12-29  Rob Buis  <buis@kde.org>
 
         Reviewed by Eric.
diff --git a/LayoutTests/fast/dom/serialize-attribute-expected.txt b/LayoutTests/fast/dom/serialize-attribute-expected.txt
new file mode 100644 (file)
index 0000000..3798643
--- /dev/null
@@ -0,0 +1,4 @@
+Test for bug 11998: Incorrect serialization of quotation marks in XML attributes.
+
+SUCCESS
+
diff --git a/LayoutTests/fast/dom/serialize-attribute.xhtml b/LayoutTests/fast/dom/serialize-attribute.xhtml
new file mode 100644 (file)
index 0000000..229e471
--- /dev/null
@@ -0,0 +1,33 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title/>
+<script>
+<![CDATA[
+function test() {
+
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+  try {
+    serialized = (new XMLSerializer()).serializeToString(document.getElementById("testDiv\"'&<>"));
+    if (serialized == "<div xmlns=\"http://www.w3.org/1999/xhtml\" id=\"testDiv&quot;'&amp;&lt;&gt;\"/>" ||
+        serialized == "<div xmlns=\"http://www.w3.org/1999/xhtml\" id=\"testDiv&quot;'&amp;&lt;&gt;\"></div>")
+      document.getElementById("result").textContent = "SUCCESS";
+    else
+      document.getElementById("result").textContent = "FAIL: " + (new XMLSerializer()).serializeToString(document.getElementsByTagName('div')[1]);
+  } catch (ex) {
+    alert(ex);
+  }
+}
+]]>
+</script>
+</head>
+<body onload="test();">
+<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=11998">bug 11998</a>:
+Incorrect serialization of quotation marks in XML attributes.</p>
+<div id="result">FAIL: cannot find an element.</div>
+
+<!-- Currently, WebKit doesn't serialize the namespace unless it's explicitly specified, bug 5262 -->
+<div xmlns="http://www.w3.org/1999/xhtml" id="testDiv&#34;&#39;&#38;&#60;&#62;"/>
+</body>
+</html>
index 4a7eab9..e3cfd9f 100644 (file)
@@ -1,3 +1,17 @@
+2006-12-30  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Mitz.
+
+        http://bugs.webkit.org/show_bug.cgi?id=11998
+        Incorrect serialization of quotation marks in XML attributes.
+
+        Test: fast/dom/serialize-attribute.xhtml
+
+        * editing/markup.cpp:
+        (WebCore::escapeTextForMarkup): Added an isAttributeValue parameter, as the quotation mark
+        only needs to be encoded in attribute values.
+        (WebCore::startMarkup): Pass appropriate isAttributeValue to escapeTextForMarkup().
+
 2006-12-29  David Kilzer  <ddkilzer@webkit.org>
 
         Build fix for no-svg build.
index 3a8e340..438da6d 100644 (file)
@@ -61,7 +61,7 @@ using namespace HTMLNames;
 
 static inline bool shouldSelfClose(const Node *node);
 
-static DeprecatedString escapeTextForMarkup(const DeprecatedString &in)
+static DeprecatedString escapeTextForMarkup(const DeprecatedString &in, bool isAttributeValue)
 {
     DeprecatedString s = "";
 
@@ -77,6 +77,12 @@ static DeprecatedString escapeTextForMarkup(const DeprecatedString &in)
             case '>':
                 s += "&gt;";
                 break;
+            case '"':
+                if (isAttributeValue) {
+                    s += "&quot;";
+                    break;
+                }
+                // fall through
             default:
                 s += in[i];
         }
@@ -163,7 +169,7 @@ static DeprecatedString startMarkup(const Node *node, const Range *range, EAnnot
             }
             bool useRenderedText = annotate && !enclosingNodeWithTag(const_cast<Node*>(node), selectTag);
             
-            DeprecatedString markup = useRenderedText ? escapeTextForMarkup(renderedText(node, range)) : escapeTextForMarkup(stringValueForRange(node, range).deprecatedString());            
+            DeprecatedString markup = useRenderedText ? escapeTextForMarkup(renderedText(node, range), false) : escapeTextForMarkup(stringValueForRange(node, range).deprecatedString(), false);
             if (defaultStyle) {
                 Node *element = node->parentNode();
                 if (element) {
@@ -237,7 +243,7 @@ static DeprecatedString startMarkup(const Node *node, const Range *range, EAnnot
                     markup += " " + attr->name().localName().deprecatedString();
                 else
                     markup += " " + attr->name().toString().deprecatedString();
-                markup += "=\"" + escapeTextForMarkup(value.deprecatedString()) + "\"";
+                markup += "=\"" + escapeTextForMarkup(value.deprecatedString(), true) + "\"";
             }
             
             if (additionalStyle.length() > 0)