Ticket #12119: 12119.smart_split_with_space.diff

File 12119.smart_split_with_space.diff, 1.2 KB (added by Johannes Dollinger, 15 years ago)
  • django/utils/text.py

     
    200200# Expression to match some_token and some_token="with spaces" (and similarly
    201201# for single-quoted strings).
    202202smart_split_re = re.compile(r"""
    203     ([^\s"]*"(?:[^"\\]*(?:\\.[^"\\]*)*)"\S*|
    204      [^\s']*'(?:[^'\\]*(?:\\.[^'\\]*)*)'\S*|
    205      \S+)""", re.VERBOSE)
     203    ((?:
     204        [^\s'"]*
     205        (?:
     206            (?:"(?:[^"\\]|\\.)*" | '(?:[^'\\]|\\.)*')
     207            [^\s'"]*
     208        )+
     209    ) | \S+)
     210""", re.VERBOSE)
    206211
    207212def smart_split(text):
    208213    r"""
  • tests/regressiontests/text/tests.py

     
    2727[u'url', u'search_page', u'words=hello']
    2828>>> list(smart_split(u'url search_page words="something else'))
    2929[u'url', u'search_page', u'words="something', u'else']
     30>>> list(smart_split("cut:','|cut:' '"))
     31[u"cut:','|cut:' '"]
    3032
    3133### urlquote #############################################################
    3234>>> from django.utils.http import urlquote, urlquote_plus
Back to Top