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

Fix issue 49043 #49782

Merged
merged 3 commits into from Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/states/file.py
Expand Up @@ -1118,7 +1118,7 @@ def _get_template_texts(source_list=None,
tmplines = None
with salt.utils.files.fopen(rndrd_templ_fn, 'rb') as fp_:
tmplines = fp_.read()
tmplines = tmplines.decode(__salt_system_encoding__)
tmplines = salt.utils.stringutils.to_unicode(tmplines)
tmplines = tmplines.splitlines(True)
if not tmplines:
msg = 'Failed to read rendered template file {0} ({1})'
Expand Down
10 changes: 5 additions & 5 deletions salt/utils/files.py
Expand Up @@ -791,10 +791,10 @@ def backup_minion(path, bkroot):
def get_encoding(path):
'''
Detect a file's encoding using the following:
- Check for ascii
- Check for Byte Order Marks (BOM)
- Check for UTF-8 Markers
- Check System Encoding
- Check for ascii

Args:

Expand Down Expand Up @@ -867,10 +867,6 @@ def check_system_encoding(_data):
except os.error:
raise CommandExecutionError('Failed to open file')

# Check for ASCII first
if check_ascii(data):
return 'ASCII'

# Check for Unicode BOM
encoding = check_bom(data)
if encoding:
Expand All @@ -884,4 +880,8 @@ def check_system_encoding(_data):
if check_system_encoding(data):
return __salt_system_encoding__

# Check for ASCII first
if check_ascii(data):
return 'ASCII'

raise CommandExecutionError('Could not detect file encoding')
1 change: 1 addition & 0 deletions tests/integration/files/file/base/issue-49043
@@ -0,0 +1 @@
{{unicode_string}}
16 changes: 16 additions & 0 deletions tests/integration/files/file/base/issue-49043.sls
@@ -0,0 +1,16 @@
somefile-exists:
file:
- managed
- name: {{ pillar['name'] }}

somefile-blockreplace:
file:
- blockreplace
- append_if_not_found: true
- name: {{ pillar['name'] }}
- template: jinja
- source: salt://issue-49043
- require:
- file: somefile-exists
- context:
unicode_string: "\xe4\xf6\xfc"
19 changes: 19 additions & 0 deletions tests/integration/states/test_file.py
Expand Up @@ -3746,6 +3746,25 @@ def test_matching_block_and_marker_not_after_newline_no_append_newline(self, nam
self._read(name),
self.with_matching_block_and_marker_end_not_after_newline)

@with_tempfile()
def test_issue_49043(self, name):
ret = self.run_function(
'state.sls',
mods='issue-49043',
pillar={'name': name},
)
log.error("ret = %s", repr(ret))
diff = '--- \n+++ \n@@ -0,0 +1,3 @@\n'
diff += dedent('''\
+#-- start managed zone --
+äöü
+#-- end managed zone --
''')
job = 'file_|-somefile-blockreplace_|-{}_|-blockreplace'.format(name)
self.assertEqual(
ret[job]['changes']['diff'],
diff)


class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
'''
Expand Down