Bug 401662 - plaintext serializer includes content of <style> elements, r+sr=mrbkap, a=dsicore
authorphilringnalda@gmail.com
Mon, 12 Nov 2007 19:15:44 -0800
changeset 7891 bb5e3f39c242a49f90cbe81842f6666eb8cbf6c8
parent 7890 16ae957deba26de243ab4a0f8a6c8b0cde5bbfab
child 7892 21dbc6ba37b0a6b96e4e646acfaf7dbaed37265c
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdsicore
bugs401662
milestone1.9b2pre
Bug 401662 - plaintext serializer includes content of <style> elements, r+sr=mrbkap, a=dsicore
content/base/src/nsPlainTextSerializer.cpp
content/base/test/Makefile.in
content/base/test/test_bug401662.html
--- a/content/base/src/nsPlainTextSerializer.cpp
+++ b/content/base/src/nsPlainTextSerializer.cpp
@@ -1065,18 +1065,20 @@ nsPlainTextSerializer::DoAddLeaf(const n
        mTagStack[mTagStackIndex-2] == eHTMLTag_select) ||
       (mTagStackIndex > 0 &&
         mTagStack[mTagStackIndex-1] == eHTMLTag_select)) {
     // Don't output the contents of SELECT elements;
     // Might be nice, eventually, to output just the selected element.
     // Read more in bug 31994.
     return NS_OK;
   }
-  else if (mTagStackIndex > 0 && mTagStack[mTagStackIndex-1] == eHTMLTag_script) {
-    // Don't output the contents of <script> tags;
+  else if (mTagStackIndex > 0 &&
+           (mTagStack[mTagStackIndex-1] == eHTMLTag_script ||
+            mTagStack[mTagStackIndex-1] == eHTMLTag_style)) {
+    // Don't output the contents of <script> or <style> tags;
     return NS_OK;
   }
   else if (type == eHTMLTag_text) {
     /* Check, if we are in a link (symbolized with mURL containing the URL)
        and the text is equal to the URL. In that case we don't want to output
        the URL twice so we scrap the text in mURL. */
     if (!mURL.IsEmpty() && mURL.Equals(aText)) {
       mURL.Truncate();
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -106,12 +106,13 @@ include $(topsrcdir)/config/rules.mk
 		file_CrossSiteXHR_pass3.xml \
 		test_bug326337.html \
 		file_bug326337_inner.html \
 		file_bug326337.xml \
 		file_bug326337_multipart.txt \
 		file_bug326337_multipart.txt^headers^ \
 		test_bug402150.html \
 		test_bug402150.html^headers^ \
+		test_bug401662.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug401662.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=401662
+-->
+<head>
+  <title>Test for Bug 401662</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=401662">Mozilla Bug 401662</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <iframe id="testframe"
+          src="data:text/html,<html><body>foo<style>bar</style></body></html>">
+  </iframe>
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 401662 - don't serialize style elements in body into
+    plaintext**/
+SimpleTest.waitForExplicitFinish();
+
+window.onload = function() {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  const Cc = Components.classes;
+  const Ci = Components.interfaces;
+
+  var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
+                   .createInstance(Ci.nsIDocumentEncoder);
+
+  var doc = $("testframe").contentDocument;
+
+  encoder.init(doc, "text/plain", encoder.OutputBodyOnly);
+  encoder.setCharset("UTF-8");
+
+  var out = encoder.encodeToString();
+
+  is(out, "foo", "style content serialized in plaintext?");
+
+  SimpleTest.finish();
+}
+</script>
+</pre>
+</body>
+</html>
+