plop
plop copied to clipboard
Append action erring on string with regex
I'm seeing the same issue that was marked closed in #178. Opening a new issue here to track the problem.
I'm running plop v2.5.3 and seeing the same issue (using the same code) as outlined in #178.
Similar regex problem while using append. plop cant find the below string and appends again. The problem is with the "(" and ")". They must be escaped while regexing before append by plop.
<Route key="AboutPage" exact path={PATHS.ABOUT_PAGE} render={(props) => <AboutPage {...props} />} />
The
the problem from @jwrudzin seems to be the "[" and "\" which must be escaped by plop to match
{handle: "[data-{{ dashCase name}}]", require: {{properCase name}} }\,
the correct regex to match the above is
{handle: "\[data-{{ dashCase name}}]", require: {{properCase name}} }\\,
per https://regexr.com/
in file append.js I made the below modification, and it seems to be working now for append. Someone may commit this maybe, I am not a familiar with source control systems.
const stringToAppendSanitized = (separator + stringToAppend).replace(/[.*+?^${}()|[\]\\]/g, "\\$&") //added by cakirlarc
// const lastPartWithoutDuplicates = lastPart.replace(new RegExp(separator + stringToAppend, 'g'), ''); //original plop
const lastPartWithoutDuplicates = lastPart.replace(new RegExp(stringToAppendSanitized, 'g'), ''); //added by cakirlarc
@jwrudzin @amwmedia
Thanks, I'll take a look at this soon
Has there been any update on this? I'm unfortunately still running into this issue even using the escaped regex string cakirlarc posted.
Looking further, there seems to have been a PR already opened for this exact issue:
https://github.com/plopjs/node-plop/pull/139
We're waiting on some tests being written but once this is done, we can merge and cut a new release
Looks like those tests were written -- any chance we can get that merged?
@bryantAXS I don't seem to see tests in the pull request in question. Am I missing something obvious?
Can someone give me an input that still throws this error? I am working on writing tests so that we can get this fix in (branch fix-append-unique
) and get get node-plop
to throw errors for either inputs:
<Route key="AboutPage" exact path={PATHS.ABOUT_PAGE} render={(props) => <AboutPage {...props} />} />
Nor
{handle: "[data-{{ dashCase name}}]", require: {{properCase name}} }\,
Tests are a good thing to get working, but useless if I can't make them fail in the un-regexed codebase
@crutchcorn sorry, I misread the pull request!
I just pulled down the latest 2.5.4
and it looks like I'm still running into the issue.
In this case the input used in the name variable is TestingForGithub
actions.push({
type: 'append',
path: 'src/scripts/app.js',
pattern: /(Components Loader -- DO NOT REMOVE COMMENT!)/gi,
template: '{handle: "[data-{{ dashCase name}}]", require: {{properCase name}} }\,',
});
The errors generated are:
✔ ++ /src/components/molecules/TestingForGithub/TestingForGithub.js
✔ _+ /src/scripts/app.js
✖ _+ Invalid regular expression: /
{handle: "[data-testing-for-github]", require: TestingForGithub },/: Range out of order in character class
✖ ++ src/components/{{lowerCase type}}/{{properCase name}}/{{properCase name}}.scss Aborted due to previous action failure
✖ ++ src/components/{{lowerCase type}}/{{properCase name}}/{{properCase name}}.twig Aborted due to previous action failure
✖ _+ src/styles/includes/{{lowerCase type}}.scss Aborted due to previous action failure
Does that help?
I'm still unable to get a failing test in node-plop
for whatever reason when trying to write tests. I'll be taking a closer look at the integration within plop
to see more specifically where the problem lies and if the PR that's been opened will really fix it. If it does, we'll merge. Just trying to do due diligence
@crutchcorn sounds good - thanks!
this can be worked around if you use the SafeString from handlebars, as such
template: new Handlebars.SafeString('special string').toString()
at least in my case it solved the issue, but this is very cumbersome
@crutchcorn Just checking to see if there's any update here? Still hoping to get this fix merged in. Thanks!
I think we can merge in a PR that I have open for this https://github.com/plopjs/node-plop/pull/164. That said, I'd like someone to test that this actually solves the problem. If someone can pull in node-plop
and plop
and do some testing on a scenario they know is broken, then I can merge and we can cut a release
The initial issue to be solved by https://github.com/plopjs/node-plop/pull/164 can be reproduced here https://codesandbox.io/s/ecstatic-dubinsky-igwz6?file=/plopfile.js
Just run npx plop
with same name three times and open the index.ts file.
any updates on this one?
Seeing the same error on ^2.7.4
with a [
character in the template string.
Tried new Handlebars.SafeString
as above, but same result.
\\
to escape the characters removes the error, but leaves a single \
in the appended content. Any help would be much appreciated 💪
I'm getting the same error in 2.7.6 with
- "deployment-templates/spring-boot/**/*"
If you want to reproduce it's as simple as adding append
action:
{
type: 'append',
path: '../.github/monorepo.yml',
templateFile: 'spring-boot/.github/monorepo.yml',
},
the template:
{{serviceName}}:
depends_on:
files:
- "deployment-templates/spring-boot/**/*"
required_checks:
- build
- test
any updates on this one? this occur plop 3.1.1 v
@siosio34 It does not seem so, the PR was moved to https://github.com/plopjs/plop/pull/330 from what I was able to find
It would be great to get https://github.com/plopjs/plop/pull/330 merged in for the next release. I spent way too long trying to troubleshoot why a template with "()" in it wasn't appending unique.