From 799dded02cc07caed77b7f24fbc516dff97d31f0 Mon Sep 17 00:00:00 2001 From: Phred Date: Sun, 3 Oct 2010 10:35:32 -0700 Subject: [PATCH] escape all regex special chars... think I got them all now --- nodemon | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nodemon b/nodemon index 784a19a..68144f3 100644 --- a/nodemon +++ b/nodemon @@ -10,9 +10,14 @@ var fs = require('fs'), monitor = null, ignoreFilePath = __dirname + '/ignore', ignoreFileTime = null, - ignoreFiles = [flag], // ignore the monitor flag by default reIgnoreFiles = null, - timeout = 1000; // check every 1 second + ignoreFiles = [flag], // ignore the monitor flag by default + timeout = 1000, // check every 1 second + // create once, reuse as needed + reComments = /#.*$/, + reTrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g, + reEscapeChars = /[.|\-[\]()]/g, + reAsterisk = /\*/g'; function startNode() { sys.log('[nodemon] starting node'); @@ -73,13 +78,13 @@ require('path').exists(ignoreFilePath, function () { if (!ignoreFileTime || (ignoreFileTime != stat.mtime)) { fs.readFileSync(ignoreFilePath).toString().split(/\n/).forEach(function (line) { // remove comments and trim lines - if (line = line.replace(/#.*$/, '').replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, '')) { + if (line = line.replace(reComments, '').replace(reTrim, '')) { ignoreFiles.push(line); } }); ignoreFileTime = stat.mtime; reIgnoreFiles = new RegExp(ignoreFiles.map(function(file) { - return file.replace(/[.|]/g, '\\$&').replace(/\*/g, '.*'); + return file.replace(reEscapeChars, '\\$&').replace(reAsterisk, '.*'); }).join('|')); } });