diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-04-10 10:37:53 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-04-10 10:37:53 +0200 |
commit | e591b0e485ca0bc833a479c612f96d283d7ac009 (patch) | |
tree | bbb8573c5712da37c4f683b037daa4e2a3fc2786 | |
parent | 334f782aa80599f4885b531548ad8661fd475ebb (diff) | |
parent | 6b56c7de7f664454ff16eb2a8ad0790c022e5a74 (diff) | |
download | gitbook-e591b0e485ca0bc833a479c612f96d283d7ac009.zip gitbook-e591b0e485ca0bc833a479c612f96d283d7ac009.tar.gz gitbook-e591b0e485ca0bc833a479c612f96d283d7ac009.tar.bz2 |
Merge pull request #696 from sindresorhus/escaperegex-module
use the `escape-string-regexp` module
-rw-r--r-- | lib/template.js | 4 | ||||
-rw-r--r-- | lib/utils/string.js | 5 | ||||
-rw-r--r-- | package.json | 3 |
3 files changed, 4 insertions, 8 deletions
diff --git a/lib/template.js b/lib/template.js index 187df87..3e6364d 100644 --- a/lib/template.js +++ b/lib/template.js @@ -2,9 +2,9 @@ var _ = require("lodash"); var Q = require("q"); var path = require("path"); var nunjucks = require("nunjucks"); +var escapeStringRegexp = require("escape-string-regexp"); var git = require("./utils/git"); -var stringUtils = require("./utils/string"); var fs = require("./utils/fs"); var batch = require("./utils/batch"); var pkg = require("../package.json"); @@ -302,7 +302,7 @@ TemplateEngine.prototype.addBlock = function(name, block) { TemplateEngine.prototype._applyShortcut = function(parser, content, shortcut) { if (!_.contains(shortcut.parsers, parser)) return content; var regex = new RegExp( - stringUtils.escapeRegex(shortcut.start) + "([\\s\\S]*?[^\\$])" + stringUtils.escapeRegex(shortcut.end), + escapeStringRegexp(shortcut.start) + "([\\s\\S]*?[^\\$])" + escapeStringRegexp(shortcut.end), 'g' ); return content.replace(regex, function(all, match) { diff --git a/lib/utils/string.js b/lib/utils/string.js index 588f4d9..72a9ca0 100644 --- a/lib/utils/string.js +++ b/lib/utils/string.js @@ -20,12 +20,7 @@ function optionsToShellArgs(options) { .join(" "); } -function escapeRegex(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); -} - module.exports = { - escapeRegex: escapeRegex, escapeShellArg: escapeShellArg, optionsToShellArgs: optionsToShellArgs, toLowerCase: String.prototype.toLowerCase.call.bind(String.prototype.toLowerCase) diff --git a/package.json b/package.json index b6303e6..b9c1305 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "npm": "2.4.1", "dom-serializer": "0.1.0", "spawn-cmd": "0.0.2", - "highlight.js": "8.4.0" + "highlight.js": "8.4.0", + "escape-string-regexp": "1.0.3" }, "devDependencies": { "mocha": "2.2.1", |