Skip to content

Commit

Permalink
Escape the filename in the array of files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukund Lakshman committed Dec 9, 2015
1 parent b67d06e commit 881d433
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BroccoliServiceWorker.prototype.write = function(readTree, destDir) {

if (!stat.isFile() && !stat.isSymbolicLink())
return;
lines.push(createArrayLine(" '"+file+"'", idx, array.length));
lines.push(createArrayLine(' "'+escapeFilename(file)+'"', idx, array.length));
});
lines.push("];");
precacheURLs.forEach(function (file, idx, array) {
Expand Down Expand Up @@ -130,6 +130,11 @@ function createArrayLine(line, idx, arrayLength) {
return arrayLine;
}

// http://stackoverflow.com/a/22837870
function escapeFilename(filename) {
return JSON.stringify(filename).slice(1, -1);
}

//From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string){
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
Expand Down

0 comments on commit 881d433

Please sign in to comment.