Fix file.line diff formatting.

Using _splitlines_preserving_trailing_newline() strips off line
endings, mangling the unified_diff output. Switching to splitlines
with the keepends option resolves this issue, while still
preserving trailing newline.

Fixes #41474
This commit is contained in:
Gabe Van Engel 2017-10-27 20:19:33 -07:00
parent ea07f9c54c
commit 24d7315f1a
No known key found for this signature in database
GPG key ID: 424CAF57744AFEDA

View file

@ -1856,10 +1856,8 @@ def line(path, content, match=None, mode=None, location=None,
if changed:
if show_changes:
with salt.utils.fopen(path, 'r') as fp_:
path_content = _splitlines_preserving_trailing_newline(
fp_.read())
changes_diff = ''.join(difflib.unified_diff(
path_content, _splitlines_preserving_trailing_newline(body)))
path_content = fp_.read().splitlines(True)
changes_diff = ''.join(difflib.unified_diff(path_content, body.splitlines(True)))
if __opts__['test'] is False:
fh_ = None
try: