Decode the non-english username str to unicode
convert the non-english username str to unicode, then the converted username can match the username from db. Fixes bug #1221576 Change-Id: I9e5f941fe43f081d75750e3f4754e8beea8210db
This commit is contained in:
@@ -99,6 +99,8 @@ def find_resource(manager, name_or_id):
|
||||
|
||||
# finally try to find entity by name
|
||||
try:
|
||||
if isinstance(name_or_id, str):
|
||||
name_or_id = name_or_id.decode('utf-8', 'strict')
|
||||
return manager.find(name=name_or_id)
|
||||
except exceptions.NotFound:
|
||||
msg = ("No %s with a name or ID of '%s' exists." %
|
||||
|
@@ -28,6 +28,7 @@ class FakeManager(object):
|
||||
resources = {
|
||||
'1234': {'name': 'entity_one'},
|
||||
'8e8ec658-c7b0-4243-bdf8-6f7f2952c0d0': {'name': 'entity_two'},
|
||||
'\xe3\x82\xbdtest': {'name': u'\u30bdtest'},
|
||||
'5678': {'name': '9876'}
|
||||
}
|
||||
|
||||
@@ -72,6 +73,11 @@ class FindResourceTestCase(test_utils.TestCase):
|
||||
output = utils.find_resource(self.manager, uuid)
|
||||
self.assertEqual(output, self.manager.resources[uuid])
|
||||
|
||||
def test_find_by_unicode(self):
|
||||
name = '\xe3\x82\xbdtest'
|
||||
output = utils.find_resource(self.manager, name)
|
||||
self.assertEqual(output, self.manager.resources[name])
|
||||
|
||||
def test_find_by_str_name(self):
|
||||
output = utils.find_resource(self.manager, 'entity_one')
|
||||
self.assertEqual(output, self.manager.resources['1234'])
|
||||
|
Reference in New Issue
Block a user