Skip to content

Commit 2d652dd

Browse files
committed
fix(generator): escape special chars for path replacements with regex
If a projects path contains special characters, they will be intrepeted as regular expresion instructions, which results in wrong output paths in the end. To avoid this, special characters that can be used in regular expressions should be escaped. Fixes #32
1 parent 7de726f commit 2d652dd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/generator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ const generateFile = options => new Promise((resolve, reject) => {
9696
const generateOperationFile = (config, operation, operation_name) => new Promise((resolve, reject) => {
9797
fs.readFile(path.join(config.root, config.file_name), 'utf8', (err, data) => {
9898
if (err) return reject(err);
99+
const escaped_templates_dir = config.templates_dir.replace(/([.*+?^$|(){}\[\]])/mg, "\\$1");
99100
const subdir = config.root
100-
.replace(new RegExp(`${config.templates_dir}[/]?`),'')
101+
.replace(new RegExp(`${escaped_templates_dir}[/]?`),'')
101102
.replace("$$path$$", _.kebabCase(operation_name));
102103

103104
const new_filename = config.file_name.replace('$$path$$', operation_name).replace(/.hbs$/, '');

0 commit comments

Comments
 (0)