-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(yaml): less aggressive jinja2 stripping #33190
base: main
Are you sure you want to change the base?
Conversation
@@ -143,7 +143,7 @@ export function dump(obj: any, opts?: DumpOptions): string { | |||
function massageContent(content: string, options?: YamlOptions): string { | |||
if (options?.removeTemplates) { | |||
return content | |||
.replace(regEx(/\s+{{.+?}}:.+/gs), '') | |||
.replace(regEx(/\n\s*{{.+?}}:\s*\n/gs), '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.replace(regEx(/\n\s*{{.+?}}:\s*\n/gs), '') | |
.replace(regEx(/^\s*{{.+?}}:\s*\n/gs), '') |
otherwise you'll remove one new line to much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will that ^ match "start of line" or "start of file"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I open the regexr link and use that regex, it no longer matches the template. The documentation for ^
mentions:
Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
So, to answer the question above, it matches the "start of file" when the multiline flag is disabled (by default).
Enabling the multiline flag makes the regex work as expected (regexr link):
.replace(regEx(/\n\s*{{.+?}}:\s*\n/gs), '') | |
.replace(regEx(/^\s*{{.+?}}:\s*\n/gms), '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single line flag is also required, so .
doesn't match newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't want .
to match newlines, you should remove the dotall flag:
.replace(regEx(/\n\s*{{.+?}}:\s*\n/gs), '') | |
.replace(regEx(/^\s*{{.+?}}:\s*\n/gm), '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're stuck again? @viceice please propose a fully working change
Changes
Context
#32967
https://regexr.com/89otc
Documentation (please check one with an [x])
How I've tested my work (please select one)
I have verified these changes via: