mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix issue 49043
This commit is contained in:
parent
413868329c
commit
2a901e960d
@ -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})'
|
||||
|
@ -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')
|
||||
|
@ -558,6 +558,8 @@ def get_diff(a, b, *args, **kwargs):
|
||||
with unicode on PY2.
|
||||
'''
|
||||
encoding = ('utf-8', 'latin-1', __salt_system_encoding__)
|
||||
if 'lineterm' not in kwargs:
|
||||
kwargs['lineterm'] = os.linesep
|
||||
# Late import to avoid circular import
|
||||
import salt.utils.data
|
||||
return ''.join(
|
||||
|
1
tests/integration/files/file/base/issue-49043
Normal file
1
tests/integration/files/file/base/issue-49043
Normal file
@ -0,0 +1 @@
|
||||
{{unicode_string}}
|
16
tests/integration/files/file/base/issue-49043.sls
Normal file
16
tests/integration/files/file/base/issue-49043.sls
Normal 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"
|
@ -3747,6 +3747,27 @@ 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 = dedent('''\
|
||||
---
|
||||
+++
|
||||
@@ -0,0 +1,3 @@
|
||||
+#-- start managed zone --
|
||||
+äöü
|
||||
+#-- end managed zone --
|
||||
''')
|
||||
job = 'file_|-somefile-blockreplace_|-{}_|-blockreplace'.format(name)
|
||||
self.assertEqual(
|
||||
ret[job]['changes']['diff'],
|
||||
diff)
|
||||
|
||||
|
||||
class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user