Repository: GoogleChrome/sw-precache (js)

Issue:
Apply dontCacheBustUrlsMatching to the pathname
Moved from https://github.com/jeffposnick/create-react-pwa/issues/14

Right now the `dontCacheBustUrlsMatching` parameter, if set, is matched against the full URL. It should only match against the URL's `pathname`, to prevent false-positives if the origin portion of the URL matches.

CC: @bgrzys

Pull request description:
Match the cache-bust check against the URL's pathname
R: @gauntface @addyosmani 
CC: @bgrzys

This was always the intention, as the pattern is meant to pick up hashes in filenames. Folks have reported that a pattern like `/\.\w{8}\./` accidentally matched against the the URL's origin for certain domain names.

This will be rolled up into the pending 5.0.0 release.

Fixes #240

Patch:
diff --git a/README.md b/README.md
index 9e57269..a111c16 100644
--- a/README.md
+++ b/README.md
@@ -349,10 +349,15 @@ is not needed, and can be safely excluded.
 `dontCacheBustUrlsMatching` gives you a way of opting-in to skipping the cache
 busting behavior for a subset of your URLs (or all of them, if a catch-all value
 like `/./` is used).
-If set, then each URL that's prefetched will be matched against this value.
+If set, then the [pathname](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname)
+of each URL that's prefetched will be matched against this value.
 If there's a match, then the URL will be prefetched as-is, without an additional
 cache-busting URL parameter appended.
 
+Note: Prior to `sw-precache` v5.0.0, `dontCacheBustUrlsMatching` matched against
+the entire request URL. As of v5.0.0, it only matches against the URL's
+[pathname](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname).
+
 _Default_: not set
 
 #### dynamicUrlToDependencies [Object&#x27e8;String,Array&#x27e8;String&#x27e9;&#x27e9;]  
diff --git a/cli.js b/cli.js
index 862d796..08a02f6 100755
--- a/cli.js
+++ b/cli.js
@@ -21,7 +21,11 @@
 
 var meow = require('meow');
 var path = require('path');
+var pkg = require('./package.json');
 var swPrecache = require('./');
+var updateNotifier = require('update-notifier');
+
+updateNotifier({pkg: pkg}).notify();
 
 function setDefaults(cli, configFileFlags) {
   var compositeFlags = cli.flags;
diff --git a/lib/functions.js b/lib/functions.js
index 54bdd4d..c485761 100644
--- a/lib/functions.js
+++ b/lib/functions.js
@@ -71,7 +71,7 @@ module.exports = {
     // If dontCacheBustUrlsMatching is not set, or if we don't have a match,
     // then add in the extra cache-busting URL parameter.
     if (!dontCacheBustUrlsMatching ||
-        !(url.toString().match(dontCacheBustUrlsMatching))) {
+        !(url.pathname.match(dontCacheBustUrlsMatching))) {
       url.search += (url.search ? '&' : '') +
         encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue);
     }
diff --git a/package.json b/package.json
index 8de35fb..f246b19 100644
--- a/package.json
+++ b/package.json
@@ -49,7 +49,8 @@
     "meow": "^3.7.0",
     "mkdirp": "^0.5.1",
     "pretty-bytes": "^4.0.2",
-    "sw-toolbox": "^3.4.0"
+    "sw-toolbox": "^3.4.0",
+    "update-notifier": "^1.0.3"
   },
   "repository": "googlechrome/sw-precache",
   "bugs": "https://github.com/googlechrome/sw-precache/issues",


Test patch:
diff --git a/test/test.js b/test/test.js
index 26b68e9..519d1b3 100644
--- a/test/test.js
+++ b/test/test.js
@@ -410,14 +410,21 @@ describe('createCacheKey', function() {
     done();
   });
 
-  it('should not append the parameter when the URL matches the exclusion pattern', function(done) {
+  it('should append the parameter when the origin matches the exclusion pattern, but the pathname does not match', function(done) {
     var url = 'http://example.com/test/path?existing=value';
     var cacheKey = externalFunctions.createCacheKey(url, 'name', 'value', /example/);
-    assert.strictEqual(cacheKey, url);
+    assert.strictEqual(cacheKey, 'http://example.com/test/path?existing=value&name=value');
+    done();
+  });
+
+  it('should not append the parameter when the pathname matches the exclusion pattern', function(done) {
+    var url = 'http://example.com/test/path?existing=value';
+    var cacheKey = externalFunctions.createCacheKey(url, 'name', 'value', /test\/path/);
+    assert.strictEqual(cacheKey, 'http://example.com/test/path?existing=value');
     done();
   });
 
-  it('should append the parameter when the URL does not match the exclusion pattern', function(done) {
+  it('should append the parameter when the pathname does not match the exclusion pattern', function(done) {
     var url = 'http://example.com/test/path?existing=value';
     var cacheKey = externalFunctions.createCacheKey(url, 'name', 'value', /no_match/);
     assert.strictEqual(cacheKey, 'http://example.com/test/path?existing=value&name=value');