[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
This commit is contained in:
Joseph Kocherhans 2010-02-24 20:56:09 +00:00
parent 07f2d19269
commit 6bf75fd3f5
2 changed files with 10 additions and 3 deletions

View File

@ -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"""

View File

@ -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