Merge pull request #49782 from dwoz/issue-49043

Fix issue 49043
This commit is contained in:
Nicole Thomas 2018-10-01 09:43:01 -04:00 committed by GitHub
commit aca87abe40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 6 deletions

View File

@ -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})'

View File

@ -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:
@ -867,10 +867,6 @@ def get_encoding(path):
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:
@ -884,4 +880,8 @@ def get_encoding(path):
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')

View File

@ -0,0 +1 @@
{{unicode_string}}

View File

@ -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"

View File

@ -3746,6 +3746,25 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
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):
'''