mask_password doesn't return unicode type value if non-ASCII characters exist in the message
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oslo.utils |
Invalid
|
Undecided
|
Unassigned |
Bug Description
mask_password doesn't return unicode type value[1] if non-ASCII characters exist in the message.
If non-ASCII characters doesn't exist in the message, mask_password returns unicode value:
>>> from oslo_utils import strutils
>>> utf8_str = u'test --password Chinese.
>>> masked = strutils.
>>> type(masked)
<type 'unicode'>
If non-ASCII characters exist in the message, mask_password returns str value:
>>> from oslo_utils import strutils
>>> utf8_str = u'test --password Chinese中文.
>>> masked = strutils.
>>> type(masked)
<type 'str'>
The uncertainty of the return type will cause an exception in the following scenario:
from oslo_serialization import jsonutils
from oslo_utils import strutils
def serialize(
utf8_data = jsonutils.
utf8_data = unicode_
return utf8_data
# scenario 1: without non-ASCII
message_dict = {u'name': u'test --password Chinese.'}
body = serialize(
# scenario 2: with non-ASCII
message_dict = {u'name': u'test --password Chinese 中文.'}
body = serialize(
NOTE: There is a way to avoid this problem by converting message to unicode before passed into mask_password:
strutils.
[1]: https:/
Changed in oslo.utils: | |
assignee: | nobody → javeme (javaloveme) |
Is there any use case in openstack projects ?