From c8cd8b80aa90f463814e1957d26e4a11f2f94414 Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Wed, 24 Feb 2010 20:52:14 +0000 Subject: [PATCH] Fixed #12119. Changed smart_split to stop splitting on whitespace in quotes. Thanks, emulbreh. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12581 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/text.py | 11 ++++++++--- tests/regressiontests/text/tests.py | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/django/utils/text.py b/django/utils/text.py index 624f5b6a55..5d633b7afe 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -202,9 +202,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