-
Notifications
You must be signed in to change notification settings - Fork 293
Description
Hello,
As in #178 , #188 , #353 , the append action has a major problem when using regexp special characters in the template and when unique is set to true (or undefined since true is the default value).
In node-plop code there is:
// append.js:23
const lastPartWithoutDuplicates = lastPart.replace(
new RegExp(separator + stringToAppend, "g"),
"",
);Since the stringToAppend variable is the rendered template without further manipulation, if the template contains some regexp special characters, the regexp might be invalid.
For example, if you define as action:
{
type: 'append',
path: 'file.json',
pattern: /"elements": {(?<insertion>)/g,
template: '"list": [ "element-list" ];',
},And your file.json is:
{
"elements": {
}
}when executed it gives the following error: Range out of order in character class. (since t-l is an invalid character range). This can be fixed by using for example: template: '"list": \\[ "element-list" ];',, but then the json generated is invalid (it prints literally "list": \[ "element-list" ]), so adding escape characters is not an option.
There was a PR fixing this: #330 but it was closed without merging.
If this happens to you, a temporary solution might be to explicitly set unique: false in your action configuration. But this is not ideal, because it means that you'll get duplicates if you run multiple times your generator.