Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
dwoz wants to merge1 commit intosaltstack:3006.x
base:3006.x
Choose a base branch
Loading
fromdwoz:issue/30690/3006.x

Conversation

@dwoz
Copy link
Contributor

@dwozdwoz commentedDec 14, 2025
edited
Loading

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.

  • 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

Fixes#30690

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
@dwozdwoz requested a review froma team as acode ownerDecember 14, 2025 02:21
@dwozdwoz added the test:fullRun the full test suite labelDec 14, 2025
return [_unescape_newlines(item)foritemindata]
elifisinstance(data,str):
# Convert literal \n (backslash-n) to actual newline
returndata.replace("\\n","\n")
Copy link
Contributor

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?

frebib reacted with thumbs up emoji
Copy link
Contributor

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
Copy link
Contributor

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?

frebib and twangboy reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@twangboytwangboytwangboy left review comments

+1 more reviewer

@bdrx312bdrx312bdrx312 left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

@dwozdwoz

Labels

test:fullRun the full test suite

Projects

None yet

Milestone

Sulfur v3006.18

Development

Successfully merging this pull request may close these issues.

Newlines may be rendered as literal \n for multi-line scalar variables in some circumstances

3 participants

@dwoz@bdrx312@twangboy

[8]ページ先頭

©2009-2025 Movatter.jp