From 2bdd3f32262ee6785e363b96552a1dd98b32bc65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A8=81=E8=80=81?= Date: Sun, 28 Sep 2014 17:48:14 +0800 Subject: [PATCH 1/3] Remove query string in dest and src --- lib/configwriter.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/configwriter.js b/lib/configwriter.js index 987b151..651a25b 100644 --- a/lib/configwriter.js +++ b/lib/configwriter.js @@ -146,6 +146,13 @@ ConfigWriter.prototype.process = function (file, config) { } lfile.blocks.forEach(function (block) { + // Remove query string in dest and src + block = _.cloneDeep(block); + block.dest = block.dest.replace(/\?.*$/g,''); + block.src.forEach(function (src, i) { + block.src[i ] = src.replace(/\?.*$/g,''); + }); + // FIXME: support several searchPath... var context = { inDir: self.root || lfile.searchPath[0], From 9df08fb6ef1571c9f34c77ff1bf4be1dc39a9263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A8=81=E8=80=81?= Date: Thu, 26 Feb 2015 11:16:03 +0800 Subject: [PATCH 2/3] Improve code style --- lib/configwriter.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/configwriter.js b/lib/configwriter.js index 651a25b..9fd6236 100644 --- a/lib/configwriter.js +++ b/lib/configwriter.js @@ -15,6 +15,11 @@ var deepMerge = function (origCfg, cfg) { return outCfg; }; +// convert url to path +var pathify = function (url) { + return url.replace(/\?.*$/g, ''); +}; + // // Create a config writer for the furnished flow. // The created config will: @@ -146,12 +151,9 @@ ConfigWriter.prototype.process = function (file, config) { } lfile.blocks.forEach(function (block) { - // Remove query string in dest and src block = _.cloneDeep(block); - block.dest = block.dest.replace(/\?.*$/g,''); - block.src.forEach(function (src, i) { - block.src[i ] = src.replace(/\?.*$/g,''); - }); + block.dest = pathify(block.dest); + block.src = block.src.map(pathify); // FIXME: support several searchPath... var context = { From b089973797feda2116f793cf1ab8336730b2b4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A8=81=E8=80=81?= Date: Thu, 26 Feb 2015 11:41:26 +0800 Subject: [PATCH 3/3] add test for block with query string in url --- .../fixtures/block_with_query_string_in_url.html | 3 +++ test/test-usemin.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/fixtures/block_with_query_string_in_url.html diff --git a/test/fixtures/block_with_query_string_in_url.html b/test/fixtures/block_with_query_string_in_url.html new file mode 100644 index 0000000..655fb83 --- /dev/null +++ b/test/fixtures/block_with_query_string_in_url.html @@ -0,0 +1,3 @@ + + + diff --git a/test/test-usemin.js b/test/test-usemin.js index cf6afe6..3a411af 100644 --- a/test/test-usemin.js +++ b/test/test-usemin.js @@ -619,6 +619,22 @@ describe('useminPrepare', function () { assert.equal(copyCfg.generated.files[0].dest, path.normalize('dist/scripts/plugins.js')); }); + it('should allow query string in url', function () { + grunt.log.muted = true; + grunt.config.init(); + grunt.config('useminPrepare', { + html: 'index.html' + }); + grunt.file.copy(path.join(__dirname, 'fixtures/block_with_query_string_in_url.html'), 'index.html'); + grunt.task.run('useminPrepare'); + grunt.task.start(); + + var concatCfg = grunt.config('concat'); + assert.ok(concatCfg); + assert.equal(concatCfg.generated.files[0].dest, path.normalize('.tmp/concat/foo.js')); + assert.deepEqual(concatCfg.generated.files[0].src, [path.normalize('baz.js')]); + }); + it('should allow to post configure generated steps', function () { var concatPostConfig = {