mirror of https://github.com/django/django.git
Fixed unescape_string_literal() crash on empty strings.
This commit is contained in:
parent
5d9c512e5b
commit
e1d673c373
|
@ -375,7 +375,7 @@ def unescape_string_literal(s):
|
|||
>>> unescape_string_literal("'\'ab\' c'")
|
||||
"'ab' c"
|
||||
"""
|
||||
if s[0] not in "\"'" or s[-1] != s[0]:
|
||||
if not s or s[0] not in "\"'" or s[-1] != s[0]:
|
||||
raise ValueError("Not a string literal: %r" % s)
|
||||
quote = s[0]
|
||||
return s[1:-1].replace(r'\%s' % quote, quote).replace(r'\\', '\\')
|
||||
|
|
|
@ -226,7 +226,7 @@ class TestUtilsText(SimpleTestCase):
|
|||
self.assertEqual(text.unescape_string_literal(lazystr(value)), output)
|
||||
|
||||
def test_unescape_string_literal_invalid_value(self):
|
||||
items = ['abc', "'abc\""]
|
||||
items = ['', 'abc', "'abc\""]
|
||||
for item in items:
|
||||
msg = f'Not a string literal: {item!r}'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
|
|
Loading…
Reference in New Issue