Skip to content
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

Properly handle latin-1 encoding in file diffs #48934

Merged
merged 12 commits into from
Aug 7, 2018

Conversation

terminalmage
Copy link
Contributor

@terminalmage terminalmage commented Aug 3, 2018

This changes the encoding/decoding helpers to attempt latin-1 after initially trying UTF-8, which prevents a traceback when displaying diffs when a file with latin-1 encoding is updated using a file.managed state.

Resolves #48777

Copy link
Contributor

@rallytime rallytime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that __salt__ is being used instead of __utils__ in a couple of places. There's some lint/test errors as well.

@@ -1567,7 +1567,7 @@ def comment_line(path,
check_perms(path, None, pre_user, pre_group, pre_mode)

# Return a diff using the two dictionaries
return ''.join(difflib.unified_diff(orig_file, new_file))
return __salt__['stringutils.get_diff'](orig_file, new_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be __utils__ instead of __salt__?

changes_diff = ''.join(difflib.unified_diff(
path_content, body
))
changes_diff = __salt__['stringutils.get_diff'](path_content, body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here as above.

@@ -2688,7 +2683,7 @@ def _add_content(linesep, lines=None, include_marker_start=True,
)

if block_found:
diff = ''.join(difflib.unified_diff(orig_file, new_file))
diff = __salt__['stringutils.get_diff'](orig_file, new_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, too?

@rallytime
Copy link
Contributor

@terminalmage This looks like the tests will need some mocking love, due to the change to __utils__.

@rallytime
Copy link
Contributor

@terminalmage Looks like one last test failure to clean up here

https://jenkinsci.saltstack.com/job/pr-kitchen-ubuntu1604-py3/job/PR-48934/4/

Since latin-1 is not being automatically decoded, we need to explicitly
pass it on the test.
@rallytime rallytime merged commit ab1a713 into saltstack:2018.3 Aug 7, 2018
@terminalmage terminalmage deleted the issue48777 branch August 7, 2018 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants