Bug 169521: fix XML attribute serialization for proper roundtripping r=bz
authorAshish Kulkarni <kulkarni.ashish@gmail.com>
Wed, 24 Jan 2018 16:03:01 +0530
changeset 402421 fe4514c84e7a
parent 402420 38898fac8d0a
child 402422 a9b041089fc6
push id33389
push usernbeleuzu@mozilla.com
push dateTue, 06 Feb 2018 09:53:43 +0000
treeherdermozilla-central@25ceb97b5773 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs169521, 418531
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 169521: fix XML attribute serialization for proper roundtripping r=bz This is due to incomplete specification, see discussion on Chromium bug https://bugs.chromium.org/p/chromium/issues/detail?id=418531 Behavior is now in line with Edge and Chromium. MozReview-Commit-ID: AxIRtIj5j8r
dom/base/nsXMLContentSerializer.cpp
testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -1204,33 +1204,36 @@ static const uint8_t kEntities[] = {
   _, _, _, _, _, _, _, _, 2, _,
   _, _, _, _, _, _, _, _, _, _,
   _, _, _, _, _, _, _, _, _, _,
   3, _, 4
 };
 
 // This table indexes into kEntityStrings[].
 static const uint8_t kAttrEntities[] = {
-  _, _, _, _, _, _, _, _, _, _,
-  _, _, _, _, _, _, _, _, _, _,
+  _, _, _, _, _, _, _, _, _, 5,
+  6, _, _, 7, _, _, _, _, _, _,
   _, _, _, _, _, _, _, _, _, _,
   _, _, _, _, 1, _, _, _, 2, _,
   _, _, _, _, _, _, _, _, _, _,
   _, _, _, _, _, _, _, _, _, _,
   3, _, 4
 };
 
 #undef _
 
 static const char* const kEntityStrings[] = {
   /* 0 */ nullptr,
   /* 1 */ "&quot;",
   /* 2 */ "&amp;",
   /* 3 */ "&lt;",
   /* 4 */ "&gt;",
+  /* 5 */ "&#9;",
+  /* 6 */ "&#xA;",
+  /* 7 */ "&#xD;",
 };
 
 bool
 nsXMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
                                                    nsAString& aOutputStr)
 {
   nsReadingIterator<char16_t> done_reading;
   aStr.EndReading(done_reading);
--- a/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
+++ b/testing/web-platform/tests/domparsing/XMLSerializer-serializeToString.html
@@ -34,11 +34,20 @@ test(function() {
 }, 'Check if the default namespace is correctly reset.');
 
 test(function() {
   var input = '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>';
   var root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
   var xmlString = (new XMLSerializer()).serializeToString(root);
   assert_equals(xmlString, '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>');
 }, 'Check if there is no redundant empty namespace declaration.');
+
+test(function() {
+  var serializer = new XMLSerializer();
+  var root = createXmlDoc().documentElement;
+  root.firstChild.setAttribute('attr1', 'value1\tvalue2\r\n');
+  var xmlString = serializer.serializeToString(root);
+  assert_equals(xmlString, '<root><child1 attr1="value1&#9;value2&#xD;&#xA;">value1</child1></root>');
+}, 'check XMLSerializer.serializeToString escapes attribute values for roundtripping');
+
 </script>
  </body>
 </html>