Code

Ticket #12119: 12119.smart_split_with_space.diff

File 12119.smart_split_with_space.diff, 1.2 KB (added by emulbreh, 4 years ago)
Line 
1Index: django/utils/text.py
2===================================================================
3--- django/utils/text.py        (revision 11680)
4+++ django/utils/text.py        (working copy)
5@@ -200,9 +200,14 @@
6 # Expression to match some_token and some_token="with spaces" (and similarly
7 # for single-quoted strings).
8 smart_split_re = re.compile(r"""
9-    ([^\s"]*"(?:[^"\\]*(?:\\.[^"\\]*)*)"\S*|
10-     [^\s']*'(?:[^'\\]*(?:\\.[^'\\]*)*)'\S*|
11-     \S+)""", re.VERBOSE)
12+    ((?:
13+        [^\s'"]*
14+        (?:
15+            (?:"(?:[^"\\]|\\.)*" | '(?:[^'\\]|\\.)*')
16+            [^\s'"]*
17+        )+
18+    ) | \S+)
19+""", re.VERBOSE)
20 
21 def smart_split(text):
22     r"""
23Index: tests/regressiontests/text/tests.py
24===================================================================
25--- tests/regressiontests/text/tests.py (revision 11680)
26+++ tests/regressiontests/text/tests.py (working copy)
27@@ -27,6 +27,8 @@
28 [u'url', u'search_page', u'words=hello']
29 >>> list(smart_split(u'url search_page words="something else'))
30 [u'url', u'search_page', u'words="something', u'else']
31+>>> list(smart_split("cut:','|cut:' '"))
32+[u"cut:','|cut:' '"]
33 
34 ### urlquote #############################################################
35 >>> from django.utils.http import urlquote, urlquote_plus