Bug 1015535 - Only consider text nodes and cdata sections as candidates for translation. r=smaug
authorFelipe Gomes <felipc@gmail.com>
Sat, 24 May 2014 23:52:04 -0300
changeset 184914 a311f34398c263d55073d70b3970b222161b0272
parent 184913 9d54afd94ff301e5973c4bd0baecdcd794890f54
child 184915 1eb359cf7ac0b955482dd36238c1fc162a6198a4
push id43971
push usercbook@mozilla.com
push dateMon, 26 May 2014 13:32:37 +0000
treeherdermozilla-inbound@76f83b6745f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1015535
milestone32.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 1015535 - Only consider text nodes and cdata sections as candidates for translation. r=smaug
content/base/src/nsGenericDOMDataNode.cpp
dom/base/test/test_getTranslationNodes.html
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -1008,16 +1008,21 @@ nsGenericDOMDataNode::TextIsOnlyWhitespa
 
   SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE | NS_TEXT_IS_ONLY_WHITESPACE);
   return true;
 }
 
 bool
 nsGenericDOMDataNode::HasTextForTranslation()
 {
+  if (NodeType() != nsIDOMNode::TEXT_NODE &&
+      NodeType() != nsIDOMNode::CDATA_SECTION_NODE) {
+    return false;
+  }
+
   if (mText.Is2b()) {
     // The fragment contains non-8bit characters which means there
     // was at least one "interesting" character to trigger non-8bit.
     return true;
   }
 
   if (HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE) &&
       HasFlag(NS_TEXT_IS_ONLY_WHITESPACE)) {
--- a/dom/base/test/test_getTranslationNodes.html
+++ b/dom/base/test/test_getTranslationNodes.html
@@ -201,10 +201,27 @@
 </div>
 
 <!-- Test that nesting of inline elements won't produce roots as long as
      the parents are in the list of translation nodes -->
 <div id="testcase15"
      expected="p[root] a b span em">
   <p>Lorem <a>ipsum <b>dolor <span>sit</span> amet</b></a>, <em>consetetur</em></p>
 </div>
+
+<!-- Test that comment nodes are not considered for translation -->
+<div id="testcase16"
+     expected="p[root] p[root]">
+  <p>Lorem ipsum</p>
+  <div>  <!-- Comment -->  </div>
+  <p>Lorem ipsum</p>
+</div>
+
+<!-- Test that comment nodes are not considered for translation -->
+<div id="testcase17"
+     expected="p[root]">
+  <div>
+    <!-- Comment -->
+    <p>Lorem Ipsum</p>
+  </div>
+</div>
 </body>
 </html>