mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #48041 from terminalmage/hashutils-fix-windows
salt.utils.hashutils: Only decode to utf-8 on Windows
This commit is contained in:
commit
6c5389189a
1 changed files with 13 additions and 4 deletions
|
@ -13,6 +13,7 @@ import random
|
|||
# Import Salt libs
|
||||
from salt.ext import six
|
||||
import salt.utils.files
|
||||
import salt.utils.platform
|
||||
import salt.utils.stringutils
|
||||
|
||||
from salt.utils.decorators.jinja import jinja_filter
|
||||
|
@ -27,7 +28,8 @@ def base64_b64encode(instr):
|
|||
newline ('\\n') characters in the encoded output.
|
||||
'''
|
||||
return salt.utils.stringutils.to_unicode(
|
||||
base64.b64encode(salt.utils.stringutils.to_bytes(instr))
|
||||
base64.b64encode(salt.utils.stringutils.to_bytes(instr)),
|
||||
encoding='utf8' if salt.utils.platform.is_windows() else None
|
||||
)
|
||||
|
||||
|
||||
|
@ -38,7 +40,10 @@ def base64_b64decode(instr):
|
|||
'''
|
||||
decoded = base64.b64decode(salt.utils.stringutils.to_bytes(instr))
|
||||
try:
|
||||
return salt.utils.stringutils.to_unicode(decoded)
|
||||
return salt.utils.stringutils.to_unicode(
|
||||
decoded,
|
||||
encoding='utf8' if salt.utils.platform.is_windows() else None
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
return decoded
|
||||
|
||||
|
@ -52,7 +57,8 @@ def base64_encodestring(instr):
|
|||
at the end of the encoded string.
|
||||
'''
|
||||
return salt.utils.stringutils.to_unicode(
|
||||
base64.encodestring(salt.utils.stringutils.to_bytes(instr))
|
||||
base64.encodestring(salt.utils.stringutils.to_bytes(instr)),
|
||||
encoding='utf8' if salt.utils.platform.is_windows() else None
|
||||
)
|
||||
|
||||
|
||||
|
@ -68,7 +74,10 @@ def base64_decodestring(instr):
|
|||
# PY2
|
||||
decoded = base64.decodestring(b)
|
||||
try:
|
||||
return salt.utils.stringutils.to_unicode(decoded)
|
||||
return salt.utils.stringutils.to_unicode(
|
||||
decoded,
|
||||
encoding='utf8' if salt.utils.platform.is_windows() else None
|
||||
)
|
||||
except UnicodeDecodeError:
|
||||
return decoded
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue