-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
Also allow for multiple encodings to be passed
In PY3 the caught exceptions now drop out of scope when leaving the for loop.
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.
It seems that __salt__
is being used instead of __utils__
in a couple of places. There's some lint/test errors as well.
salt/modules/file.py
Outdated
@@ -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) |
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.
Should this be __utils__
instead of __salt__
?
salt/modules/file.py
Outdated
changes_diff = ''.join(difflib.unified_diff( | ||
path_content, body | ||
)) | ||
changes_diff = __salt__['stringutils.get_diff'](path_content, body) |
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.
Same question here as above.
salt/modules/file.py
Outdated
@@ -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) |
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.
Here, too?
@terminalmage This looks like the tests will need some mocking love, due to the change to |
@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.
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