From f70a339ca448f80de5445d8210529b8e21ea4045 Mon Sep 17 00:00:00 2001 From: artemkaint Date: Mon, 15 Aug 2016 08:10:50 +0000 Subject: [PATCH 1/2] Fix dot in regexp --- package.json | 21 ++++++++++++--------- src/index.js | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 89b1625..7255e81 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,12 @@ "repository": "arbolista-dev/babel-plugin-react-templates", "license": "MIT", "main": "lib/index.js", - "contributors": [{ - "name": "Eric Hulburd", - "email": "eric@arbol.org" - }], + "contributors": [ + { + "name": "Eric Hulburd", + "email": "eric@arbol.org" + } + ], "author": { "name": "Arbolista Development", "website": "http://www.arbolista.mx" @@ -17,14 +19,15 @@ "url": "https://github.com/arbolista-dev/babel-plugin-react-templates/issues" }, "dependencies": { + "babel-cli": "^6.3.17", + "babel-core": "^6.5.2", + "babel-preset-es2015": "^6.3.13", "babylon": "^6.3.0", - "react-templates": "0.5.x", + "escape-string-regexp": "^1.0.5", + "lodash": "^4.6.0", "react": "^0.14.0", "react-dom": "^0.14.0", - "lodash": "^4.6.0", - "babel-cli": "^6.3.17", - "babel-core": "^6.5.2", - "babel-preset-es2015": "^6.3.13" + "react-templates": "0.5.x" }, "devDependencies": { "jasmine": "2.4.1" diff --git a/src/index.js b/src/index.js index 3ca26f8..a632990 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import reactTemplates from 'react-templates/src/reactTemplates'; import url from 'url'; import fs from 'fs'; import path from 'path'; +import escapeRegExp from 'escape-string-regexp'; let DEFAULT_RT_OPTIONS = { targetVersion: '0.14.0', @@ -39,7 +40,7 @@ module.exports = function ({types: t}) { enter(node_path, plugin) { let relative_path = node_path.node.source.value, ext = plugin.opts.ext || '.rt.html', - reg_ext = new RegExp(ext + '$'); + reg_ext = new RegExp(escapeRegExp(ext) + '$'); if (reg_ext.test(relative_path)){ let compiled_path = fnCompiledTemplate(node_path, plugin, { relative_path: relative_path, From 189c3c3000087fdd80f8622cb5a4cb607f42ba9f Mon Sep 17 00:00:00 2001 From: artemkaint Date: Mon, 15 Aug 2016 08:26:20 +0000 Subject: [PATCH 2/2] Fix dot in regexp --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index a632990..6e50ba2 100644 --- a/src/index.js +++ b/src/index.js @@ -62,7 +62,7 @@ module.exports = function ({types: t}) { let args = node_path.node.arguments if (args.length && t.isStringLiteral(args[0])){ var ext = plugin.opts.ext || '.rt.html', - reg_ext = new RegExp(ext + '$'), + reg_ext = new RegExp(escapeRegExp(ext) + '$'), relative_path = args[0].value; if (reg_ext.test(relative_path)){ let compiled_path = fnCompiledTemplate(node_path, plugin, {