Bug 983871 - Make appcache validate hit the right URI when patch starts with / r=pbrosset
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Fri, 02 May 2014 13:27:10 +0100
changeset 206021 d0eff5655df235cc00dfcdd8520ccd6562c691b1
parent 206020 531774aeb6c2bc4ff3ea293b8a3ef96ad8cbc2b2
child 206022 ede61596f87281d1a912769c851af428abbe698f
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbrosset
bugs983871
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 983871 - Make appcache validate hit the right URI when patch starts with / r=pbrosset
browser/devtools/shared/AppCacheUtils.jsm
--- a/browser/devtools/shared/AppCacheUtils.jsm
+++ b/browser/devtools/shared/AppCacheUtils.jsm
@@ -177,17 +177,16 @@ AppCacheUtils.prototype = {
 
     return deferred.promise;
   },
 
   _getURIInfo: function ACU__getURIInfo(uri) {
     let inputStream = Cc["@mozilla.org/scriptableinputstream;1"]
                         .createInstance(Ci.nsIScriptableInputStream);
     let deferred = promise.defer();
-    let channelCharset = "";
     let buffer = "";
     let channel = Services.io.newChannel(uri, null, null);
 
     // Avoid the cache:
     channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
     channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
 
     channel.asyncOpen({
@@ -198,17 +197,17 @@ AppCacheUtils.prototype = {
 
       onDataAvailable: function (request, context, stream, offset, count) {
         request.QueryInterface(Ci.nsIHttpChannel);
         inputStream.init(stream);
         buffer = buffer.concat(inputStream.read(count));
       },
 
       onStopRequest: function onStartRequest(request, context, statusCode) {
-        if (statusCode == 0) {
+        if (statusCode === 0) {
           request.QueryInterface(Ci.nsIHttpChannel);
 
           let result = {
             name: request.name,
             success: request.requestSucceeded,
             status: request.responseStatus + " - " + request.responseStatusText,
             charset: request.contentCharset || "utf-8",
             mimeType: request.contentType,
@@ -274,17 +273,17 @@ AppCacheUtils.prototype = {
             entry[key] = value;
           }
           entries.push(entry);
         }
         return true;
       }
     });
 
-    if (entries.length == 0) {
+    if (entries.length === 0) {
       throw new Error(l10n.GetStringFromName("noResults"));
     }
     return entries;
   },
 
   viewEntry: function ACU_viewEntry(key) {
     let uri;
 
@@ -315,35 +314,41 @@ AppCacheUtils.prototype = {
 
   clearAll: function ACU_clearAll() {
     Services.cache.evictEntries(Ci.nsICache.STORE_OFFLINE);
   },
 
   _getManifestURI: function ACU__getManifestURI() {
     let deferred = promise.defer();
 
-    let getURI = node => {
+    let getURI = () => {
       let htmlNode = this.doc.querySelector("html[manifest]");
       if (htmlNode) {
         let pageUri = this.doc.location ? this.doc.location.href : this.uri;
         let origin = pageUri.substr(0, pageUri.lastIndexOf("/") + 1);
-        return origin + htmlNode.getAttribute("manifest");
+        let manifestURI = htmlNode.getAttribute("manifest");
+
+        if (manifestURI.startsWith("/")) {
+          manifestURI = manifestURI.substr(1);
+        }
+
+        return origin + manifestURI;
       }
     };
 
     if (this.doc) {
-      let uri = getURI(this.doc);
+      let uri = getURI();
       return promise.resolve(uri);
     } else {
       this._getURIInfo(this.uri).then(uriInfo => {
         if (uriInfo.success) {
           let html = uriInfo.text;
           let parser = _DOMParser;
           this.doc = parser.parseFromString(html, "text/html");
-          let uri = getURI(this.doc);
+          let uri = getURI();
           deferred.resolve(uri);
         } else {
           this.errors.push({
             line: 0,
             msg: l10n.GetStringFromName("invalidURI")
           });
         }
       });
@@ -389,20 +394,20 @@ ManifestParser.prototype = {
     let fallbacks = this.fallbacks = [];
     let settings = this.settings = [];
     let errors = this.errors = [];
     let uris = this.uris = [];
 
     this.currSection = "CACHE";
 
     for (let i = 0; i < lines.length; i++) {
-      let text = this.text = lines[i].replace(/^\s+|\s+$/g);
+      let text = this.text = lines[i].trim();
       this.currentLine = i + 1;
 
-      if (i == 0 && text != "CACHE MANIFEST") {
+      if (i === 0 && text !== "CACHE MANIFEST") {
         this._addError(1, "firstLineMustBeCacheManifest", 1);
       }
 
       // Ignore comments
       if (/^#/.test(text) || !text.length) {
         continue;
       }
 
@@ -448,17 +453,17 @@ ManifestParser.prototype = {
         this._addError(this.currentLine, "asteriskInWrongSection2",
                        this.currSection, this.currentLine);
         return;
       }
     }
 
     if (/\s/.test(text)) {
       this._addError(this.currentLine, "escapeSpaces", this.currentLine);
-      text = text.replace(/\s/g, "%20")
+      text = text.replace(/\s/g, "%20");
     }
 
     if (text[0] == "/") {
       if (text.substr(0, 4) == "/../") {
         this._addError(this.currentLine, "slashDotDotSlashBad", this.currentLine);
       } else {
         this.uris.push(this._wrapURI(this.origin + text.substring(1)));
       }
@@ -501,17 +506,17 @@ ManifestParser.prototype = {
     let [ namespace, fallback ] = split;
 
     if (namespace.indexOf("*") != -1) {
       this._addError(this.currentLine, "fallbackAsterisk2", this.currentLine);
     }
 
     if (/\s/.test(namespace)) {
       this._addError(this.currentLine, "escapeSpaces", this.currentLine);
-      namespace = namespace.replace(/\s/g, "%20")
+      namespace = namespace.replace(/\s/g, "%20");
     }
 
     if (namespace.substr(0, 4) == "/../") {
       this._addError(this.currentLine, "slashDotDotSlashBad", this.currentLine);
     }
 
     if (namespace.substr(0, 2) == "./") {
       namespace = this.origin + namespace.substring(2);