Skip to content

Commit

Permalink
Fixed #12119. Changed smart_split to stop splitting on whitespace in …
Browse files Browse the repository at this point in the history
…quotes. Thanks, emulbreh.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12581 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jkocherhans committed Feb 24, 2010
1 parent 3304afa commit c8cd8b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions django/utils/text.py
Expand Up @@ -202,9 +202,14 @@ def fix(match):
# 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"""
Expand Down
2 changes: 2 additions & 0 deletions tests/regressiontests/text/tests.py
Expand Up @@ -27,6 +27,8 @@
[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
Expand Down

0 comments on commit c8cd8b8

Please sign in to comment.