Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20231 -- Don't use allow_lazy on smart_split

  • Loading branch information...
commit e7b9c11c3f87e235e643c340d38325fbd4257047 1 parent 118faa0
Baptiste Mispelon authored April 10, 2013 claudep committed April 10, 2013
1  django/utils/text.py
@@ -356,7 +356,6 @@ def smart_split(text):
356 356
     text = force_text(text)
357 357
     for bit in smart_split_re.finditer(text):
358 358
         yield bit.group(0)
359  
-smart_split = allow_lazy(smart_split, six.text_type)
360 359
 
361 360
 def _replace_entity(match):
362 361
     text = match.group(1)
70  tests/text/tests.py
@@ -2,12 +2,16 @@
2 2
 from __future__ import unicode_literals
3 3
 
4 4
 from django.test import TestCase
5  
-from django.utils.encoding import iri_to_uri
  5
+from django.utils.encoding import iri_to_uri, force_text
  6
+from django.utils.functional import lazy
6 7
 from django.utils.http import (cookie_date, http_date,
7 8
     urlquote, urlquote_plus, urlunquote, urlunquote_plus)
  9
+from django.utils import six
8 10
 from django.utils.text import get_text_list, smart_split
9 11
 from django.utils.translation import override
10 12
 
  13
+lazystr = lazy(force_text, six.text_type)
  14
+
11 15
 
12 16
 class TextTests(TestCase):
13 17
     """
@@ -25,40 +29,36 @@ def test_get_text_list(self):
25 29
 
26 30
     def test_smart_split(self):
27 31
 
28  
-        self.assertEqual(list(smart_split(r'''This is "a person" test.''')),
29  
-            ['This', 'is', '"a person"', 'test.'])
30  
-
31  
-        self.assertEqual(list(smart_split(r'''This is "a person's" test.'''))[2],
32  
-            '"a person\'s"')
33  
-
34  
-        self.assertEqual(list(smart_split(r'''This is "a person\"s" test.'''))[2],
35  
-            '"a person\\"s"')
36  
-
37  
-        self.assertEqual(list(smart_split('''"a 'one''')), ['"a', "'one"])
38  
-
39  
-        self.assertEqual(list(smart_split(r'''all friends' tests'''))[1],
40  
-            "friends'")
41  
-
42  
-        self.assertEqual(list(smart_split('url search_page words="something else"')),
43  
-            ['url', 'search_page', 'words="something else"'])
44  
-
45  
-        self.assertEqual(list(smart_split("url search_page words='something else'")),
46  
-            ['url', 'search_page', "words='something else'"])
47  
-
48  
-        self.assertEqual(list(smart_split('url search_page words "something else"')),
49  
-            ['url', 'search_page', 'words', '"something else"'])
50  
-
51  
-        self.assertEqual(list(smart_split('url search_page words-"something else"')),
52  
-            ['url', 'search_page', 'words-"something else"'])
53  
-
54  
-        self.assertEqual(list(smart_split('url search_page words=hello')),
55  
-            ['url', 'search_page', 'words=hello'])
56  
-
57  
-        self.assertEqual(list(smart_split('url search_page words="something else')),
58  
-            ['url', 'search_page', 'words="something', 'else'])
59  
-
60  
-        self.assertEqual(list(smart_split("cut:','|cut:' '")),
61  
-            ["cut:','|cut:' '"])
  32
+        testdata = [
  33
+            ('This is "a person" test.',
  34
+                ['This', 'is', '"a person"', 'test.']),
  35
+            ('This is "a person\'s" test.',
  36
+                ['This', 'is', '"a person\'s"', 'test.']),
  37
+            ('This is "a person\\"s" test.',
  38
+                ['This', 'is', '"a person\\"s"', 'test.']),
  39
+            ('"a \'one',
  40
+                ['"a', "'one"]),
  41
+            ('all friends\' tests',
  42
+                ['all', 'friends\'', 'tests']),
  43
+            ('url search_page words="something else"',
  44
+                ['url', 'search_page', 'words="something else"']),
  45
+            ("url search_page words='something else'",
  46
+                ['url', 'search_page', "words='something else'"]),
  47
+            ('url search_page words "something else"',
  48
+                ['url', 'search_page', 'words', '"something else"']),
  49
+            ('url search_page words-"something else"',
  50
+                ['url', 'search_page', 'words-"something else"']),
  51
+            ('url search_page words=hello',
  52
+                ['url', 'search_page', 'words=hello']),
  53
+            ('url search_page words="something else',
  54
+                ['url', 'search_page', 'words="something', 'else']),
  55
+            ("cut:','|cut:' '",
  56
+                ["cut:','|cut:' '"]),
  57
+            (lazystr("a b c d"),  # Test for #20231
  58
+                ['a', 'b', 'c', 'd']),
  59
+        ]
  60
+        for test, expected in testdata:
  61
+            self.assertEqual(list(smart_split(test)), expected)
62 62
 
63 63
     def test_urlquote(self):
64 64
         self.assertEqual(urlquote('Paris & Orl\xe9ans'),

0 notes on commit e7b9c11

Please sign in to comment.
Something went wrong with that request. Please try again.