- Notifications
You must be signed in to change notification settings - Fork5.6k
Fix #30690: Preserve newlines in import_yaml multi-line scalars#68535
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:3006.x
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
When using import_yaml to load YAML data with multi-line scalars (using |),the newlines were being rendered as literal \n instead of actual newlineswhen passed through Jinja templates.This fix adds an _unescape_newlines function that recursively convertsliteral \n sequences back to actual newlines in the context dictionarybefore it's used for templating.- Added _unescape_newlines function to salt/utils/templates.py- Applied unescape to context before creating decoded_context- Updated test to remove to_dict filter reference
| return [_unescape_newlines(item)foritemindata] | ||
| elifisinstance(data,str): | ||
| # Convert literal \n (backslash-n) to actual newline | ||
| returndata.replace("\\n","\n") |
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.
What happens if someone had escaped the\ in the data like\\n? With this change is there a way to get a literal\n anymore?
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.
What happens on Windows? Does it need to also look for\\r\\n? Maybe need to useos.linesep instead?
| fromsalt.loader.contextimportNamedLoaderContext | ||
| fromsalt.loader.dunderimport__file_client__ | ||
| fromsalt.utils.decorators.jinjaimportJinjaFilter,JinjaGlobal,JinjaTest | ||
| fromsalt.utils.odictimportOrderedDict |
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.
This doesn't look right. Wasn't odict deprecated?
Uh oh!
There was an error while loading.Please reload this page.
When using import_yaml to load YAML data with multi-line scalars (using |), the newlines were being rendered as literal \n instead of actual newlines when passed through Jinja templates.
This fix adds an _unescape_newlines function that recursively converts literal \n sequences back to actual newlines in the context dictionary before it's used for templating.
Fixes#30690