Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

We're using hashresh with the has in query string, but was not working properly #60

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
- "4.3.0"
- "5.6.0"
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"test": "node ./node_modules/vows/bin/vows --spec"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.7",
"grunt": "0.4.1",
"grunt-vows": "0.3.1",
"vows": "~0.7",
"grunt-contrib-jshint": "0.11.0",
"grunt": "0.4.5",
"grunt-vows": "~0.4.0",
"vows": "0.8.1",
"grunt-cli": "~0.1.6"
},
"keywords": [
Expand Down
4 changes: 3 additions & 1 deletion tasks/hashresHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/subfolders-querystring/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<link rel="stylesheet" href="styles/mystyles1.css">
<link rel="stylesheet" href="styles/mystyles2.css">
<script type="text/javascript" src="scripts/myscripts1.js"></script>
<script type="text/javascript" src="scripts/myscripts2.js"></script>
</head>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/subfolders-querystring/scripts/myscripts1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
// Nothing to do
})
3 changes: 3 additions & 0 deletions test/fixtures/subfolders-querystring/scripts/myscripts2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
// Nothing to do
})
1 change: 1 addition & 0 deletions test/fixtures/subfolders-querystring/styles/mystyles1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.style {}
1 change: 1 addition & 0 deletions test/fixtures/subfolders-querystring/styles/mystyles2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.style {}
8 changes: 8 additions & 0 deletions test/fixtures/subfolders-querystring2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<link rel="stylesheet" href="styles/mystyles1.css?v=3b97b071-123456">
<link rel="stylesheet" href="styles/mystyles2.css?v=3b97b071-123456">
<script type="text/javascript" src="scripts/myscripts1.js?v=5a7a5b61-qwerty"></script>
<script type="text/javascript" src="scripts/myscripts2.js?v=5a7a5b61-=dhjj"></script>
</head>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/subfolders-querystring2/scripts/myscripts1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
// Nothing to do
})
3 changes: 3 additions & 0 deletions test/fixtures/subfolders-querystring2/scripts/myscripts2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
// Nothing to do
})
1 change: 1 addition & 0 deletions test/fixtures/subfolders-querystring2/styles/mystyles1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.style {}
1 change: 1 addition & 0 deletions test/fixtures/subfolders-querystring2/styles/mystyles2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.style {}
44 changes: 43 additions & 1 deletion test/hashresHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,48 @@ 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
});

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);