Bug 358452 - Make the behavior of space, tab, carriage return and line feed in title attribute tooltips HTML5-compliant / IE-compatible. r=dao
authorHenri Sivonen <hsivonen@iki.fi>
Wed, 25 Jan 2012 10:59:36 +0000
changeset 86557 fa01b899854a2ba1ed337ba6411aed1051bd78e2
parent 86556 93e51ab759cbbb189ef9b89a0af3b46262eec1f1
child 86558 0d5ad6a6f814daabf70822accbdcd05619b4bcd5
child 86574 707d41d9ba05246ea3eb31ed449eb0ef810b125f
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs358452
milestone12.0a1
Bug 358452 - Make the behavior of space, tab, carriage return and line feed in title attribute tooltips HTML5-compliant / IE-compatible. r=dao
browser/base/content/browser.js
browser/base/content/test/browser_bug329212.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -3107,30 +3107,23 @@ function FillInHTMLTooltip(tipElement)
     tipElement = tipElement.parentNode;
   }
 
   var tipNode = document.getElementById("aHTMLTooltip");
   tipNode.style.direction = direction;
 
   [titleText, XLinkTitleText, SVGTitleText].forEach(function (t) {
     if (t && /\S/.test(t)) {
-
-      // Per HTML 4.01 6.2 (CDATA section), literal CRs and tabs should be
-      // replaced with spaces, and LFs should be removed entirely.
-      // XXX Bug 322270: We don't preserve the result of entities like &#13;,
-      // which should result in a line break in the tooltip, because we can't
-      // distinguish that from a literal character in the source by this point.
-      t = t.replace(/[\r\t]/g, ' ');
-      t = t.replace(/\n/g, '');
+      // Make CRLF and CR render one line break each.  
+      t = t.replace(/\r\n?/g, '\n');
 
       tipNode.setAttribute("label", t);
       retVal = true;
     }
   });
-
   return retVal;
 }
 
 var browserDragAndDrop = {
   canDropLink: function (aEvent) Services.droppedLinkHandler.canDropLink(aEvent, true),
 
   dragOver: function (aEvent)
   {
--- a/browser/base/content/test/browser_bug329212.js
+++ b/browser/base/content/test/browser_bug329212.js
@@ -6,26 +6,26 @@ function test () {
 
     let doc = gBrowser.contentDocument;
     let tooltip = document.getElementById("aHTMLTooltip");
 
     ok(FillInHTMLTooltip(doc.getElementById("svg1"), "should get title"));
     is(tooltip.getAttribute("label"), "This is a non-root SVG element title");
 
     ok(FillInHTMLTooltip(doc.getElementById("text1"), "should get title"));
-    is(tooltip.getAttribute("label"), "    This            is a title    ");
+    is(tooltip.getAttribute("label"), "\n\n\n    This            is a title\n\n    ");
 
     ok(!FillInHTMLTooltip(doc.getElementById("text2"), "should not get title"));
 
     ok(!FillInHTMLTooltip(doc.getElementById("text3"), "should not get title"));
 
     ok(FillInHTMLTooltip(doc.getElementById("link1"), "should get title"));
-    is(tooltip.getAttribute("label"), "      This is a title    ");
+    is(tooltip.getAttribute("label"), "\n      This is a title\n    ");
     ok(FillInHTMLTooltip(doc.getElementById("text4"), "should get title"));
-    is(tooltip.getAttribute("label"), "      This is a title    ");
+    is(tooltip.getAttribute("label"), "\n      This is a title\n    ");
 
     ok(!FillInHTMLTooltip(doc.getElementById("link2"), "should not get title"));
 
     ok(FillInHTMLTooltip(doc.getElementById("link3"), "should get title"));
     ok(tooltip.getAttribute("label") != "");
 
     ok(FillInHTMLTooltip(doc.getElementById("link4"), "should get title"));
     is(tooltip.getAttribute("label"), "This is an xlink:title attribute");