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

Commit

Permalink
Merge pull request #16 from crodas/patch-1
Browse files Browse the repository at this point in the history
Escape filename
  • Loading branch information
Luismahou committed Nov 6, 2013
2 parents d7337a2 + d519edb commit 8927e41
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tasks/hashresHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ var fs = require('fs'),
path = require('path'),
utils = require('./hashresUtils');

function preg_quote (str, delimiter) {
// http://kevin.vanzonneveld.net
// + original by: booeyOH
// + improved by: Ates Goral (http://magnetiq.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + improved by: Brett Zamir (http://brett-zamir.me)
// * example 1: preg_quote("$40");
// * returns 1: '\$40'
// * example 2: preg_quote("*RRRING* Hello?");
// * returns 2: '\*RRRING\* Hello\?'
// * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:");
// * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:'
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
}

exports.hashAndSub = function(grunt, options) {

var src = options.src,
Expand Down Expand Up @@ -55,7 +71,7 @@ exports.hashAndSub = function(grunt, options) {
var destContents = fs.readFileSync(f, encoding);
for (var name in nameToHashedName) {
grunt.log.debug('Substituting ' + name + ' by ' + nameToHashedName[name]);
destContents = destContents.replace(new RegExp(name, "g"), nameToHashedName[name]);
destContents = destContents.replace(new RegExp(preg_quote(name), "g"), nameToHashedName[name]);
}
grunt.log.debug('Saving the updated contents of the outination file');
fs.writeFileSync(f, destContents, encoding);
Expand Down

0 comments on commit 8927e41

Please sign in to comment.