Merge "reject problematic object names"

This commit is contained in:
Jenkins 2014-10-29 16:47:43 +00:00 committed by Gerrit Code Review
commit 3b6dcfa467
2 changed files with 6 additions and 1 deletions

View File

@ -306,7 +306,8 @@ def check_utf8(string):
if isinstance(string, unicode):
string.encode('utf-8')
else:
string.decode('UTF-8')
if string.decode('UTF-8').encode('UTF-8') != string:
return False
return '\x00' not in string
# If string is unicode, decode() will raise UnicodeEncodeError
# So, we should catch both UnicodeDecodeError & UnicodeEncodeError

View File

@ -416,6 +416,10 @@ class TestConstraints(unittest.TestCase):
valid_utf8_str]:
self.assertTrue(constraints.check_utf8(true_argument))
def test_check_utf8_non_canonical(self):
self.assertFalse(constraints.check_utf8('\xed\xa0\xbc\xed\xbc\xb8'))
self.assertFalse(constraints.check_utf8('\xed\xa0\xbd\xed\xb9\x88'))
def test_validate_bad_meta(self):
req = Request.blank(
'/v/a/c/o',