ms2ger avatar ms2ger committed 01751a5 Draft

Escape <, > and & in XML serialization.

Fixes <https://www.w3.org/Bugs/Public/show_bug.cgi?id=18437&gt;.

Comments (0)

Files changed (3)

       <li>Let <var title="">markup</var> be the concatenation of
       "<code title="">&lt;![CDATA[</code>", <var title="">data</var>, and
       "<code title="">]]&gt;</code>".
-
-      <li>Return <var title="">markup</var>.
     </ol>
 
-    <p>Otherwise, return <var title="">data</var>.
+    <p>Otherwise, run the following steps:
+    <ol>
+      <li>Let <var title="">markup</var> be <var title="">data</var>.
+      <li>Replace any occurrences of "<code title="">&amp;</code>" in
+      <var title="">markup</var> by "<code title="">&amp;amp;</code>".
+      <li>Replace any occurrences of "<code title="">&lt;</code>" in
+      <var title="">markup</var> by "<code title="">&amp;lt;</code>".
+      <li>Replace any occurrences of "<code title="">&gt;</code>" in
+      <var title="">markup</var> by "<code title="">&amp;gt;</code>".
+    </ol>
+
+    <p>Return <var title="">markup</var>.
 
   <dt><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#documentfragment><code class=external data-anolis-spec=dom>DocumentFragment</code></a>
   <dd>
       <li>Let <var title>markup</var> be the concatenation of
       "<code title>&lt;![CDATA[</code>", <var title>data</var>, and
       "<code title>]]></code>".
-
-      <li>Return <var title>markup</var>.
     </ol>
 
-    <p>Otherwise, return <var title>data</var>.
+    <p>Otherwise, run the following steps:
+    <ol>
+      <li>Let <var title>markup</var> be <var title>data</var>.
+      <li>Replace any occurrences of "<code title>&amp;</code>" in
+      <var title>markup</var> by "<code title>&amp;amp;</code>".
+      <li>Replace any occurrences of "<code title>&lt;</code>" in
+      <var title>markup</var> by "<code title>&amp;lt;</code>".
+      <li>Replace any occurrences of "<code title>&gt;</code>" in
+      <var title>markup</var> by "<code title>&amp;gt;</code>".
+    </ol>
+
+    <p>Return <var title>markup</var>.
 
   <dt><code data-anolis-spec=dom>DocumentFragment</code>
   <dd>

tests/innerhtml-03.xhtml

+<?xml version="1.0" encoding="UTF-8" ?>
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <title>innerHTML in XHTML</title>
   el.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "html:br"));
   assert_equals(el.innerHTML, "<html:br xmlns:html=\"http://www.w3.org/1999/xhtml\" />");
 })
+test(function() {
+  var el = document.createElement("div");
+  el.appendChild(document.createTextNode("<>\"'&"));
+  assert_equals(el.innerHTML, "&lt;&gt;\"'&amp;");
+})
+test(function() {
+  var el = document.createElement("div");
+  el.appendChild(document.createTextNode("&lt;&gt;&quot;&apos;&amp;"));
+  assert_equals(el.innerHTML, "&amp;lt;&amp;gt;&amp;quot;&amp;apos;&amp;amp;");
+})
+test(function() {
+  var el = document.createElement("div");
+  el.appendChild(document.createTextNode("àו…\u00A0"));
+  assert_equals(el.innerHTML, "àו…\u00A0");
+})
 ]]></script>
 </body>
 </html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.