summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2010-02-24 20:56:09 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2010-02-24 20:56:09 +0000
commit6bf75fd3f57c2074e2612d714cb73e66194dd46a (patch)
treec2aeca1f6f09bddc570c4251c4e86bebc99f7521
parent07f2d19269e1c4ff3b1a2ad04ce5501434488d36 (diff)
[1.1.X] Fixed #12119. Changed smart_split to stop splitting on whitespace in quotes. Backport of r12581 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12582 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/utils/text.py11
-rw-r--r--tests/regressiontests/text/tests.py2
2 files changed, 10 insertions, 3 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index 37599c15be..7592cead09 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -200,9 +200,14 @@ javascript_quote = allow_lazy(javascript_quote, unicode)
# Expression to match some_token and some_token="with spaces" (and similarly
# for single-quoted strings).
smart_split_re = re.compile(r"""
- ([^\s"]*"(?:[^"\\]*(?:\\.[^"\\]*)*)"\S*|
- [^\s']*'(?:[^'\\]*(?:\\.[^'\\]*)*)'\S*|
- \S+)""", re.VERBOSE)
+ ((?:
+ [^\s'"]*
+ (?:
+ (?:"(?:[^"\\]|\\.)*" | '(?:[^'\\]|\\.)*')
+ [^\s'"]*
+ )+
+ ) | \S+)
+""", re.VERBOSE)
def smart_split(text):
r"""
diff --git a/tests/regressiontests/text/tests.py b/tests/regressiontests/text/tests.py
index 09b8c30398..82cb1267d1 100644
--- a/tests/regressiontests/text/tests.py
+++ b/tests/regressiontests/text/tests.py
@@ -27,6 +27,8 @@ friends'
[u'url', u'search_page', u'words=hello']
>>> list(smart_split(u'url search_page words="something else'))
[u'url', u'search_page', u'words="something', u'else']
+>>> list(smart_split("cut:','|cut:' '"))
+[u"cut:','|cut:' '"]
### urlquote #############################################################
>>> from django.utils.http import urlquote, urlquote_plus