Backed out changeset d1578fd6f7e4 (bug 1342348)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Mon, 27 Feb 2017 15:25:18 +0100
changeset 490186 e35c7e3eb3cc6ab342159612bd57ac194adf9b65
parent 490185 46e57ca6f77ed0b70739e56ba77893f2751f0a89
child 490187 0edea4787f1b441247b20ab0ef180c85538cd750
push id47030
push userbmo:ttromey@mozilla.com
push dateMon, 27 Feb 2017 20:32:32 +0000
bugs1342348
milestone54.0a1
backs outd1578fd6f7e482744ad9c1a839cf922f5a58abcc
Backed out changeset d1578fd6f7e4 (bug 1342348)
toolkit/components/reader/AboutReader.jsm
--- a/toolkit/components/reader/AboutReader.jsm
+++ b/toolkit/components/reader/AboutReader.jsm
@@ -734,16 +734,31 @@ AboutReader.prototype = {
 
       // The native locale could be set differently than the article's text direction.
       var localeDirection = gChromeRegistry.isLocaleRTL("global") ? "rtl" : "ltr";
       this._readTimeElement.setAttribute("dir", localeDirection);
       this._readTimeElement.style.textAlign = article.dir == "rtl" ? "right" : "left";
     }
   },
 
+  _fixLocalLinks() {
+    // We need to do this because preprocessing the content through nsIParserUtils
+    // gives back a DOM with a <base> element. That influences how these URLs get
+    // resolved, making them no longer match the document URI (which is
+    // about:reader?url=...). To fix this, make all the hash URIs absolute. This
+    // is hacky, but the alternative of removing the base element has potential
+    // security implications if Readability has not successfully made all the URLs
+    // absolute, so we pick just fixing these in-document links explicitly.
+    let localLinks = this._contentElement.querySelectorAll("a[href^='#']");
+    for (let localLink of localLinks) {
+      // Have to get the attribute because .href provides an absolute URI.
+      localLink.href = this._doc.documentURI + localLink.getAttribute("href");
+    }
+  },
+
   _formatReadTime(slowEstimate, fastEstimate) {
     let displayStringKey = "aboutReader.estimatedReadTimeRange1";
 
     // only show one reading estimate when they are the same value
     if (slowEstimate == fastEstimate) {
       displayStringKey = "aboutReader.estimatedReadTimeValue1";
     }
 
@@ -799,16 +814,17 @@ AboutReader.prototype = {
     this._headerElement.style.display = "block";
 
     let parserUtils = Cc["@mozilla.org/parserutils;1"].getService(Ci.nsIParserUtils);
     let contentFragment = parserUtils.parseFragment(article.content,
       Ci.nsIParserUtils.SanitizerDropForms | Ci.nsIParserUtils.SanitizerAllowStyle,
       false, articleUri, this._contentElement);
     this._contentElement.innerHTML = "";
     this._contentElement.appendChild(contentFragment);
+    this._fixLocalLinks();
     this._maybeSetTextDirection(article);
     this._foundLanguage(article.language);
 
     this._contentElement.style.display = "block";
     this._updateImageMargins();
 
     this._requestFavicon();
     this._doc.body.classList.add("loaded");