diff --git a/AUTHORS b/AUTHORS index 900335efbc..ad269d3f3b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -64,6 +64,7 @@ answer newbie questions, and generally made Django that much better: Chris Chamberlin Amit Chakradeo ChaosKCW + ivan.chelubeev@gmail.com Ian Clelland crankycoder@gmail.com Matt Croydon diff --git a/django/utils/text.py b/django/utils/text.py index faf8705fa9..e75abc5638 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -191,14 +191,15 @@ def smart_split(text): Supports both single and double quotes, and supports escaping quotes with backslashes. In the output, strings will keep their initial and trailing quote marks. - >>> list(smart_split('This is "a person\'s" test.')) - ['This', 'is', '"a person\'s"', 'test.'] + + >>> list(smart_split('This is "a person\'s" test.')) + ['This', 'is', '"a person\'s"', 'test.'] """ for bit in smart_split_re.finditer(text): bit = bit.group(0) - if bit[0] == '"': + if bit[0] == '"' and bit[-1] == '"': yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"' - elif bit[0] == "'": + elif bit[0] == "'" and bit[-1] == "'": yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'" else: yield bit diff --git a/tests/regressiontests/text/__init__.py b/tests/regressiontests/text/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/text/models.py b/tests/regressiontests/text/models.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/text/tests.py b/tests/regressiontests/text/tests.py new file mode 100644 index 0000000000..f758ecaf90 --- /dev/null +++ b/tests/regressiontests/text/tests.py @@ -0,0 +1,17 @@ +""" +# Tests for stuff in django.utils.text. + +>>> from django.utils.text import * + +### smart_split ########################################################### +>>> list(smart_split(r'''This is "a person" test.''')) +['This', 'is', '"a person"', 'test.'] +>>> print list(smart_split(r'''This is "a person's" test.'''))[2] +"a person's" +>>> print list(smart_split(r'''This is "a person\\"s" test.'''))[2] +"a person"s" +>>> list(smart_split('''"a 'one''')) +['"a', "'one"] +>>> print list(smart_split(r'''all friends' tests'''))[1] +friends' +"""