From 2f6a76339910a70a612b2a2395c81fe12789d9a6 Mon Sep 17 00:00:00 2001 From: BernsteinA Date: Wed, 3 Feb 2016 12:10:59 -0500 Subject: [PATCH 1/3] fix for url (#foo) and url("") --- gulp-make-css-url-version/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gulp-make-css-url-version/index.js b/gulp-make-css-url-version/index.js index be48142..ea9f780 100644 --- a/gulp-make-css-url-version/index.js +++ b/gulp-make-css-url-version/index.js @@ -68,11 +68,10 @@ module.exports = function (options) { var promises = []; html = html.replace(/url\("?([^\)"]+)"?\)/g, function (str, url) { + + url = url.replace(/['"]*/g, "").replace(/#[\s\S]*$/,''); - url = url.replace(/\?[\s\S]*$/, "").trim(); - url = url.replace(/['"]*/g, ""); - - if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/') { + if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/' || url === '') { return str; } @@ -84,12 +83,11 @@ module.exports = function (options) { } //use md5 - var safeUrl = url.replace(/#[\s\S]*$/,''); var imageFilePath; if (options.assetsDir) { - imageFilePath = path.join(options.assetsDir, safeUrl); + imageFilePath = path.join(options.assetsDir, url); } else { - imageFilePath = path.resolve(path.dirname(file.path), safeUrl); + imageFilePath = path.resolve(path.dirname(file.path), url); } var tempKey = Math.random().toString(); From 83604f4b7359554918b2213d9a30b332946778b0 Mon Sep 17 00:00:00 2001 From: Aaron Bernstein Date: Mon, 8 Feb 2016 15:59:20 -0500 Subject: [PATCH 2/3] Revert "fix for url (#foo) and url("")" This reverts commit 2f6a76339910a70a612b2a2395c81fe12789d9a6. --- gulp-make-css-url-version/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gulp-make-css-url-version/index.js b/gulp-make-css-url-version/index.js index ea9f780..be48142 100644 --- a/gulp-make-css-url-version/index.js +++ b/gulp-make-css-url-version/index.js @@ -68,10 +68,11 @@ module.exports = function (options) { var promises = []; html = html.replace(/url\("?([^\)"]+)"?\)/g, function (str, url) { - - url = url.replace(/['"]*/g, "").replace(/#[\s\S]*$/,''); - if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/' || url === '') { + url = url.replace(/\?[\s\S]*$/, "").trim(); + url = url.replace(/['"]*/g, ""); + + if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/') { return str; } @@ -83,11 +84,12 @@ module.exports = function (options) { } //use md5 + var safeUrl = url.replace(/#[\s\S]*$/,''); var imageFilePath; if (options.assetsDir) { - imageFilePath = path.join(options.assetsDir, url); + imageFilePath = path.join(options.assetsDir, safeUrl); } else { - imageFilePath = path.resolve(path.dirname(file.path), url); + imageFilePath = path.resolve(path.dirname(file.path), safeUrl); } var tempKey = Math.random().toString(); From 2e7a1d950d665cadb45ea9605a18568944643c33 Mon Sep 17 00:00:00 2001 From: Aaron Bernstein Date: Mon, 8 Feb 2016 16:02:43 -0500 Subject: [PATCH 3/3] a better fix --- gulp-make-css-url-version/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gulp-make-css-url-version/index.js b/gulp-make-css-url-version/index.js index be48142..c26ae79 100644 --- a/gulp-make-css-url-version/index.js +++ b/gulp-make-css-url-version/index.js @@ -67,12 +67,12 @@ module.exports = function (options) { var promises = []; - html = html.replace(/url\("?([^\)"]+)"?\)/g, function (str, url) { + html = html.replace(/url\(["|']?([^\)#"']+)["|']?\)/g, function (str, url) { url = url.replace(/\?[\s\S]*$/, "").trim(); url = url.replace(/['"]*/g, ""); - if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/') { + if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/' || url === '') { return str; }