Make ResourceClass.normalize_name handle sharp S

Fixes ResourceClass.normalize_name to produce the same result in py2 and
py3 even when sharp S ('ß') is part of the input.

We do this by waiting until after replacing non-alphanumerics to upcase.

Change-Id: I431fa29d36d0d633374973fc25168344042d6c1a
Closes-Bug: #1762789
This commit is contained in:
Eric Fried 2018-04-10 12:24:40 -05:00
parent 443980399b
commit 7fd2de85b6
2 changed files with 7 additions and 12 deletions

View File

@ -58,11 +58,11 @@ class ResourceClass(fields.StringField):
def normalize_name(cls, rc_name):
if rc_name is None:
return None
norm_name = rc_name.upper()
cust_prefix = cls.CUSTOM_NAMESPACE
norm_name = cust_prefix + norm_name
# Replace some punctuation characters with underscores
norm_name = re.sub('[^0-9A-Z]+', '_', norm_name)
# Replace non-alphanumeric characters with underscores
norm_name = re.sub('[^0-9A-Za-z]+', '_', rc_name)
# Bug #1762789: Do .upper after replacing non alphanumerics.
norm_name = norm_name.upper()
norm_name = cls.CUSTOM_NAMESPACE + norm_name
return norm_name

View File

@ -370,13 +370,8 @@ class TestResourceClass(TestString):
py3. Make sure normalize_name handles it properly.
"""
name = u'Fu\xdfball'
if six.PY2:
self.assertEqual(u'CUSTOM_FU_BALL',
rc_fields.ResourceClass.normalize_name(name))
else:
# TODO(efried): When bug #1762789 is resolved, remove this branch.
self.assertEqual(u'CUSTOM_FUSSBALL',
rc_fields.ResourceClass.normalize_name(name))
self.assertEqual(u'CUSTOM_FU_BALL',
rc_fields.ResourceClass.normalize_name(name))
class TestInteger(TestField):