From 7c9e98b5ca6d265ccb0173073580ddb5abac02d4 Mon Sep 17 00:00:00 2001 From: domenicoven Date: Wed, 3 Feb 2016 15:16:14 +0100 Subject: [PATCH 01/11] Using hashres also in query string: added tests to prove the regex was not matching the query string, solved the bug, all tests still passing --- tasks/hashresHelper.js | 4 +- .../subfolders-querystring/index.html | 8 +++ .../scripts/myscripts1.js | 3 + .../scripts/myscripts2.js | 3 + .../styles/mystyles1.css | 1 + .../styles/mystyles2.css | 1 + .../subfolders-querystring2/index.html | 8 +++ .../scripts/myscripts1.js | 3 + .../scripts/myscripts2.js | 3 + .../styles/mystyles1.css | 1 + .../styles/mystyles2.css | 1 + test/hashresHelper.spec.js | 60 ++++++++++++++++++- 12 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/subfolders-querystring/index.html create mode 100644 test/fixtures/subfolders-querystring/scripts/myscripts1.js create mode 100644 test/fixtures/subfolders-querystring/scripts/myscripts2.js create mode 100644 test/fixtures/subfolders-querystring/styles/mystyles1.css create mode 100644 test/fixtures/subfolders-querystring/styles/mystyles2.css create mode 100644 test/fixtures/subfolders-querystring2/index.html create mode 100644 test/fixtures/subfolders-querystring2/scripts/myscripts1.js create mode 100644 test/fixtures/subfolders-querystring2/scripts/myscripts2.js create mode 100644 test/fixtures/subfolders-querystring2/styles/mystyles1.css create mode 100644 test/fixtures/subfolders-querystring2/styles/mystyles2.css diff --git a/tasks/hashresHelper.js b/tasks/hashresHelper.js index b30bcc8..0cfac0a 100644 --- a/tasks/hashresHelper.js +++ b/tasks/hashresHelper.js @@ -78,7 +78,9 @@ exports.hashAndSub = function(grunt, options) { var destContents = fs.readFileSync(f, encoding); files.forEach(function(value) { grunt.log.debug('Substituting ' + value[0] + ' by ' + value[1]) - destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z]+)?", "g"), value[1]); + //destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z]+)?", "g"), value[1]); + destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z\?=-]+)?", "g"), value[1]); + grunt.log.debug('Substituting ' + nameToNameSearch[value[0]] + ' by ' + value[1]) destContents = destContents.replace( diff --git a/test/fixtures/subfolders-querystring/index.html b/test/fixtures/subfolders-querystring/index.html new file mode 100644 index 0000000..ce01886 --- /dev/null +++ b/test/fixtures/subfolders-querystring/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/scripts/myscripts1.js b/test/fixtures/subfolders-querystring/scripts/myscripts1.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring/scripts/myscripts1.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/scripts/myscripts2.js b/test/fixtures/subfolders-querystring/scripts/myscripts2.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring/scripts/myscripts2.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/styles/mystyles1.css b/test/fixtures/subfolders-querystring/styles/mystyles1.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring/styles/mystyles1.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring/styles/mystyles2.css b/test/fixtures/subfolders-querystring/styles/mystyles2.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring/styles/mystyles2.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/index.html b/test/fixtures/subfolders-querystring2/index.html new file mode 100644 index 0000000..5d2e646 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/scripts/myscripts1.js b/test/fixtures/subfolders-querystring2/scripts/myscripts1.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/scripts/myscripts1.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/scripts/myscripts2.js b/test/fixtures/subfolders-querystring2/scripts/myscripts2.js new file mode 100644 index 0000000..1001058 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/scripts/myscripts2.js @@ -0,0 +1,3 @@ +(function() { + // Nothing to do +}) \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/styles/mystyles1.css b/test/fixtures/subfolders-querystring2/styles/mystyles1.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/styles/mystyles1.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/fixtures/subfolders-querystring2/styles/mystyles2.css b/test/fixtures/subfolders-querystring2/styles/mystyles2.css new file mode 100644 index 0000000..63e5c49 --- /dev/null +++ b/test/fixtures/subfolders-querystring2/styles/mystyles2.css @@ -0,0 +1 @@ +.style {} \ No newline at end of file diff --git a/test/hashresHelper.spec.js b/test/hashresHelper.spec.js index 6e104f0..0a4cc7c 100644 --- a/test/hashresHelper.spec.js +++ b/test/hashresHelper.spec.js @@ -60,6 +60,64 @@ vows.describe('hashresHelper').addBatch({ assert(html.indexOf('scripts/5a7a5b61-myscripts2.js') !== -1); assert(html.indexOf('styles/3b97b071-mystyles1.css') !== -1); assert(html.indexOf('styles/3b97b071-mystyles2.css') !== -1); + }, +'for using has as querystring': function(grunt) { + helper.hashAndSub( + grunt, { + files: [{ + src : grunt.file.expand([ + './temp/helper/subfolders-querystring/scripts/*.js', + './temp/helper/subfolders-querystring/styles/mystyles1.css', + './temp/helper/subfolders-querystring/styles/mystyles2.css']), + dest: './temp/helper/subfolders-querystring/index.html' + }], + fileNameFormat: '${name}.${ext}?v=${hash}', + encoding : 'utf8', + renameFiles : true + }); + var html = fs.readFileSync('./temp/helper/subfolders-querystring/index.html', 'utf8'); + assert(html.indexOf('scripts/myscripts1.js?v=5a7a5b61') !== -1); + assert(html.indexOf('scripts/myscripts2.js?v=5a7a5b61') !== -1); + assert(html.indexOf('styles/mystyles1.css?v=3b97b071') !== -1); + assert(html.indexOf('styles/mystyles2.css?v=3b97b071') !== -1); + }, +'for using has as querystring twice or multiple times': function(grunt) { + helper.hashAndSub( + grunt, { + files: [{ + src : grunt.file.expand([ + './temp/helper/subfolders-querystring2/scripts/*.js', + './temp/helper/subfolders-querystring2/styles/mystyles1.css', + './temp/helper/subfolders-querystring2/styles/mystyles2.css']), + dest: './temp/helper/subfolders-querystring2/index.html' + }], + fileNameFormat: '${name}.${ext}?v=${hash}', + encoding : 'utf8', + renameFiles : true + }); + +/* + helper.hashAndSub( + grunt, { + files: [{ + src : grunt.file.expand([ + './temp/helper/subfolders-querystring2/scripts/*.js', + './temp/helper/subfolders-querystring2/styles/mystyles1.css', + './temp/helper/subfolders-querystring2/styles/mystyles2.css']), + dest: './temp/helper/subfolders-querystring2/index.html' + }], + fileNameFormat: '${name}.${ext}?v=${hash}', + encoding : 'utf8', + renameFiles : true + }); + +*/ + var html = fs.readFileSync('./temp/helper/subfolders-querystring2/index.html', 'utf8'); + assert(html.indexOf('"scripts/myscripts1.js?v=5a7a5b61"') !== -1); + assert(html.indexOf('"scripts/myscripts2.js?v=5a7a5b61"') !== -1); + assert(html.indexOf('"styles/mystyles1.css?v=3b97b071"') !== -1); + assert(html.indexOf('"styles/mystyles2.css?v=3b97b071"') !== -1); } - } +} + }).export(module); \ No newline at end of file From b6e99299e998495af131620ab91f0e2f0281b2bb Mon Sep 17 00:00:00 2001 From: domenicoven Date: Wed, 3 Feb 2016 15:18:04 +0100 Subject: [PATCH 02/11] using hashresh also in query string: added tests to prove the regex was not matching the query string, solved the bug, all tests still passing --- test/hashresHelper.spec.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/test/hashresHelper.spec.js b/test/hashresHelper.spec.js index 0a4cc7c..cb616e3 100644 --- a/test/hashresHelper.spec.js +++ b/test/hashresHelper.spec.js @@ -95,23 +95,7 @@ vows.describe('hashresHelper').addBatch({ encoding : 'utf8', renameFiles : true }); - -/* - helper.hashAndSub( - grunt, { - files: [{ - src : grunt.file.expand([ - './temp/helper/subfolders-querystring2/scripts/*.js', - './temp/helper/subfolders-querystring2/styles/mystyles1.css', - './temp/helper/subfolders-querystring2/styles/mystyles2.css']), - dest: './temp/helper/subfolders-querystring2/index.html' - }], - fileNameFormat: '${name}.${ext}?v=${hash}', - encoding : 'utf8', - renameFiles : true - }); - -*/ + var html = fs.readFileSync('./temp/helper/subfolders-querystring2/index.html', 'utf8'); assert(html.indexOf('"scripts/myscripts1.js?v=5a7a5b61"') !== -1); assert(html.indexOf('"scripts/myscripts2.js?v=5a7a5b61"') !== -1); From 745adb91295a5ba75ccb3567defd6692fb4a7996 Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 15:32:27 +0100 Subject: [PATCH 03/11] Update package.json --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e002d38..ba6e1e9 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ "test": "node ./node_modules/vows/bin/vows --spec" }, "devDependencies": { - "grunt-contrib-jshint": "~0.7", + "grunt-contrib-jshint": "~0.12", "grunt": "0.4.1", - "grunt-vows": "0.3.1", - "vows": "~0.7", + "grunt-vows": "^0.4.2", + "vows": "^0.9.0-rc3", "grunt-cli": "~0.1.6" }, "keywords": [ From 37e444151cc253c2783f79d20ab50d0aa88aae17 Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 15:37:51 +0100 Subject: [PATCH 04/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba6e1e9..a63ba2d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "test": "node ./node_modules/vows/bin/vows --spec" }, "devDependencies": { - "grunt-contrib-jshint": "~0.12", + "grunt-contrib-jshint": "~0.12.0", "grunt": "0.4.1", "grunt-vows": "^0.4.2", "vows": "^0.9.0-rc3", From b5205141166b4e962afca14405e59df79f53060f Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 15:45:32 +0100 Subject: [PATCH 05/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a63ba2d..de85924 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "devDependencies": { "grunt-contrib-jshint": "~0.12.0", "grunt": "0.4.1", - "grunt-vows": "^0.4.2", + "grunt-vows": "~0.4.0", "vows": "^0.9.0-rc3", "grunt-cli": "~0.1.6" }, From 151524f94e91229f5fe49d8dd7cec0a1134d5774 Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 15:51:10 +0100 Subject: [PATCH 06/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index de85924..6135957 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "grunt-contrib-jshint": "~0.12.0", "grunt": "0.4.1", "grunt-vows": "~0.4.0", - "vows": "^0.9.0-rc3", + "vows": "^0.8.1", "grunt-cli": "~0.1.6" }, "keywords": [ From a340910aceb23f7da848943cd90c62630cbc8d72 Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 15:55:45 +0100 Subject: [PATCH 07/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6135957..6cecd4c 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "grunt-contrib-jshint": "~0.12.0", "grunt": "0.4.1", "grunt-vows": "~0.4.0", - "vows": "^0.8.1", + "vows": "0.8.1", "grunt-cli": "~0.1.6" }, "keywords": [ From 0e5e033a49451fc95daee35c8db770f84a9e96c5 Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 16:03:43 +0100 Subject: [PATCH 08/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6cecd4c..28fe22b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "test": "node ./node_modules/vows/bin/vows --spec" }, "devDependencies": { - "grunt-contrib-jshint": "~0.12.0", + "grunt-contrib-jshint": "~0.11.0", "grunt": "0.4.1", "grunt-vows": "~0.4.0", "vows": "0.8.1", From 5be1862c79cf4dbbcd5e70c3c457899733c994ea Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 16:12:53 +0100 Subject: [PATCH 09/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28fe22b..8ce4abd 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "test": "node ./node_modules/vows/bin/vows --spec" }, "devDependencies": { - "grunt-contrib-jshint": "~0.11.0", + "grunt-contrib-jshint": "0.11.0", "grunt": "0.4.1", "grunt-vows": "~0.4.0", "vows": "0.8.1", From f29c762b0f683839ce21ac7cc5eace03edf2e47b Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 17:31:51 +0100 Subject: [PATCH 10/11] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ce4abd..5d38485 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "devDependencies": { "grunt-contrib-jshint": "0.11.0", - "grunt": "0.4.1", + "grunt": "0.4.5", "grunt-vows": "~0.4.0", "vows": "0.8.1", "grunt-cli": "~0.1.6" From 71dcd05dda3e7afa099f73c0da09019238b6d5fa Mon Sep 17 00:00:00 2001 From: domenicoven Date: Thu, 11 Feb 2016 17:38:15 +0100 Subject: [PATCH 11/11] Update .travis.yml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4a83e22..19c4e52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,5 @@ language: node_js node_js: - "0.11" - "0.10" - - "0.8" + - "4.3.0" + - "5.6.0"