diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-03-30 11:57:50 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-03-30 11:57:50 +0000 |
| commit | 5e739219de63328c13e14d60732ced4f28c033b9 (patch) | |
| tree | 39eb9ae279384b99d898faf506b759d856197411 | |
| parent | 63a629bb8dd55a7976d7a71a93966f5e0c05ca5c (diff) | |
Fixed #3733 -- Fixed up quote parsing in smart_split(). Thanks, Ivan Chelubeev.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4870 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/utils/text.py | 9 | ||||
| -rw-r--r-- | tests/regressiontests/text/__init__.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/text/models.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/text/tests.py | 17 |
5 files changed, 23 insertions, 4 deletions
@@ -64,6 +64,7 @@ answer newbie questions, and generally made Django that much better: Chris Chamberlin <dja@cdc.msbx.net> Amit Chakradeo <http://amit.chakradeo.net/> ChaosKCW + ivan.chelubeev@gmail.com Ian Clelland <clelland@gmail.com> crankycoder@gmail.com Matt Croydon <http://www.postneo.com/> 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 --- /dev/null +++ b/tests/regressiontests/text/__init__.py diff --git a/tests/regressiontests/text/models.py b/tests/regressiontests/text/models.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/text/models.py 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' +""" |
