Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes #17173 -- Added some extra regression tests for reversing names…

…paced urls with special characters

The actual code was already fixed between 1.3.1 and trunk, but more thorough tests are always a good thing. Thanks for the patch, Yann Kaiser.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17075 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b745fc0f4b43280e5c5e10a52b3f3feaf3b58c2b 1 parent 7f658a5
Chris Beaven authored
2  tests/regressiontests/urlpatterns_reverse/included_namespace_urls.py
@@ -12,6 +12,8 @@
12 12
     url(r'^normal/$', 'empty_view', name='inc-normal-view'),
13 13
     url(r'^normal/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view', name='inc-normal-view'),
14 14
 
  15
+    url(r'^\+\\\$\*/$', 'empty_view', name='inc-special-view'),
  16
+
15 17
     url(r'^mixed_args/(\d+)/(?P<arg2>\d+)/$', 'empty_view', name='inc-mixed-args'),
16 18
     url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='inc-no-kwargs'),
17 19
 
4  tests/regressiontests/urlpatterns_reverse/namespace_urls.py
@@ -14,6 +14,7 @@ def urls(self):
14 14
         return patterns('',
15 15
             url(r'^inner/$', 'empty_view', name='urlobject-view'),
16 16
             url(r'^inner/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view', name='urlobject-view'),
  17
+            url(r'^inner/\+\\\$\*/$', 'empty_view', name='urlobject-special-view'),
17 18
         ), self.app_name, self.namespace
18 19
     urls = property(urls)
19 20
 
@@ -28,6 +29,8 @@ def urls(self):
28 29
     url(r'^normal/$', 'empty_view', name='normal-view'),
29 30
     url(r'^normal/(?P<arg1>\d+)/(?P<arg2>\d+)/$', 'empty_view', name='normal-view'),
30 31
 
  32
+    url(r'^\+\\\$\*/$', 'empty_view', name='special-view'),
  33
+
31 34
     url(r'^mixed_args/(\d+)/(?P<arg2>\d+)/$', 'empty_view', name='mixed-args'),
32 35
     url(r'^no_kwargs/(\d+)/(\d+)/$', 'empty_view', name='no-kwargs'),
33 36
 
@@ -50,4 +53,5 @@ def urls(self):
50 53
 
51 54
     (r'^ns-outer/(?P<outer>\d+)/', include('regressiontests.urlpatterns_reverse.included_namespace_urls', namespace='inc-outer')),
52 55
 
  56
+    (r'^\+\\\$\*/', include('regressiontests.urlpatterns_reverse.namespace_urls', namespace='special')),
53 57
 )
19  tests/regressiontests/urlpatterns_reverse/tests.py
@@ -294,30 +294,35 @@ def test_normal_name(self):
294 294
         self.assertEqual('/normal/', reverse('normal-view'))
295 295
         self.assertEqual('/normal/37/42/', reverse('normal-view', args=[37,42]))
296 296
         self.assertEqual('/normal/42/37/', reverse('normal-view', kwargs={'arg1':42, 'arg2':37}))
  297
+        self.assertEqual('/+%5C$*/', reverse('special-view'))
297 298
 
298 299
     def test_simple_included_name(self):
299 300
         "Normal lookups work on names included from other patterns"
300 301
         self.assertEqual('/included/normal/', reverse('inc-normal-view'))
301 302
         self.assertEqual('/included/normal/37/42/', reverse('inc-normal-view', args=[37,42]))
302 303
         self.assertEqual('/included/normal/42/37/', reverse('inc-normal-view', kwargs={'arg1':42, 'arg2':37}))
  304
+        self.assertEqual('/included/+%5C$*/', reverse('inc-special-view'))
303 305
 
304 306
     def test_namespace_object(self):
305 307
         "Dynamic URL objects can be found using a namespace"
306 308
         self.assertEqual('/test1/inner/', reverse('test-ns1:urlobject-view'))
307 309
         self.assertEqual('/test1/inner/37/42/', reverse('test-ns1:urlobject-view', args=[37,42]))
308 310
         self.assertEqual('/test1/inner/42/37/', reverse('test-ns1:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
  311
+        self.assertEqual('/test1/inner/+%5C$*/', reverse('test-ns1:urlobject-special-view'))
309 312
 
310 313
     def test_embedded_namespace_object(self):
311 314
         "Namespaces can be installed anywhere in the URL pattern tree"
312 315
         self.assertEqual('/included/test3/inner/', reverse('test-ns3:urlobject-view'))
313 316
         self.assertEqual('/included/test3/inner/37/42/', reverse('test-ns3:urlobject-view', args=[37,42]))
314 317
         self.assertEqual('/included/test3/inner/42/37/', reverse('test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
  318
+        self.assertEqual('/included/test3/inner/+%5C$*/', reverse('test-ns3:urlobject-special-view'))
315 319
 
316 320
     def test_namespace_pattern(self):
317 321
         "Namespaces can be applied to include()'d urlpatterns"
318 322
         self.assertEqual('/ns-included1/normal/', reverse('inc-ns1:inc-normal-view'))
319 323
         self.assertEqual('/ns-included1/normal/37/42/', reverse('inc-ns1:inc-normal-view', args=[37,42]))
320 324
         self.assertEqual('/ns-included1/normal/42/37/', reverse('inc-ns1:inc-normal-view', kwargs={'arg1':42, 'arg2':37}))
  325
+        self.assertEqual('/ns-included1/+%5C$*/', reverse('inc-ns1:inc-special-view'))
321 326
 
322 327
     def test_namespace_pattern_with_variable_prefix(self):
323 328
         "When using a include with namespaces when there is a regex variable in front of it"
@@ -325,40 +330,54 @@ def test_namespace_pattern_with_variable_prefix(self):
325 330
         self.assertEqual('/ns-outer/42/normal/', reverse('inc-outer:inc-normal-view', args=[42]))
326 331
         self.assertEqual('/ns-outer/42/normal/37/4/', reverse('inc-outer:inc-normal-view', kwargs={'outer':42, 'arg1': 37, 'arg2': 4}))
327 332
         self.assertEqual('/ns-outer/42/normal/37/4/', reverse('inc-outer:inc-normal-view', args=[42, 37, 4]))
  333
+        self.assertEqual('/ns-outer/42/+%5C$*/', reverse('inc-outer:inc-special-view',  kwargs={'outer':42}))
  334
+        self.assertEqual('/ns-outer/42/+%5C$*/', reverse('inc-outer:inc-special-view',  args=[42]))
328 335
 
329 336
     def test_multiple_namespace_pattern(self):
330 337
         "Namespaces can be embedded"
331 338
         self.assertEqual('/ns-included1/test3/inner/', reverse('inc-ns1:test-ns3:urlobject-view'))
332 339
         self.assertEqual('/ns-included1/test3/inner/37/42/', reverse('inc-ns1:test-ns3:urlobject-view', args=[37,42]))
333 340
         self.assertEqual('/ns-included1/test3/inner/42/37/', reverse('inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
  341
+        self.assertEqual('/ns-included1/test3/inner/+%5C$*/', reverse('inc-ns1:test-ns3:urlobject-special-view'))
334 342
 
335 343
     def test_nested_namespace_pattern(self):
336 344
         "Namespaces can be nested"
337 345
         self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view'))
338 346
         self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/37/42/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', args=[37,42]))
339 347
         self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/42/37/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
  348
+        self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/+%5C$*/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-special-view'))
340 349
 
341 350
     def test_app_lookup_object(self):
342 351
         "A default application namespace can be used for lookup"
343 352
         self.assertEqual('/default/inner/', reverse('testapp:urlobject-view'))
344 353
         self.assertEqual('/default/inner/37/42/', reverse('testapp:urlobject-view', args=[37,42]))
345 354
         self.assertEqual('/default/inner/42/37/', reverse('testapp:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
  355
+        self.assertEqual('/default/inner/+%5C$*/', reverse('testapp:urlobject-special-view'))
346 356
 
347 357
     def test_app_lookup_object_with_default(self):
348 358
         "A default application namespace is sensitive to the 'current' app can be used for lookup"
349 359
         self.assertEqual('/included/test3/inner/', reverse('testapp:urlobject-view', current_app='test-ns3'))
350 360
         self.assertEqual('/included/test3/inner/37/42/', reverse('testapp:urlobject-view', args=[37,42], current_app='test-ns3'))
351 361
         self.assertEqual('/included/test3/inner/42/37/', reverse('testapp:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='test-ns3'))
  362
+        self.assertEqual('/included/test3/inner/+%5C$*/', reverse('testapp:urlobject-special-view', current_app='test-ns3'))
352 363
 
353 364
     def test_app_lookup_object_without_default(self):
354 365
         "An application namespace without a default is sensitive to the 'current' app can be used for lookup"
355 366
         self.assertEqual('/other2/inner/', reverse('nodefault:urlobject-view'))
356 367
         self.assertEqual('/other2/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42]))
357 368
         self.assertEqual('/other2/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
  369
+        self.assertEqual('/other2/inner/+%5C$*/', reverse('nodefault:urlobject-special-view'))
358 370
 
359 371
         self.assertEqual('/other1/inner/', reverse('nodefault:urlobject-view', current_app='other-ns1'))
360 372
         self.assertEqual('/other1/inner/37/42/', reverse('nodefault:urlobject-view', args=[37,42], current_app='other-ns1'))
361 373
         self.assertEqual('/other1/inner/42/37/', reverse('nodefault:urlobject-view', kwargs={'arg1':42, 'arg2':37}, current_app='other-ns1'))
  374
+        self.assertEqual('/other1/inner/+%5C$*/', reverse('nodefault:urlobject-special-view', current_app='other-ns1'))
  375
+
  376
+    def test_special_chars_namespace(self):
  377
+        self.assertEqual('/+%5C$*/included/normal/', reverse('special:inc-normal-view'))
  378
+        self.assertEqual('/+%5C$*/included/normal/37/42/', reverse('special:inc-normal-view', args=[37,42]))
  379
+        self.assertEqual('/+%5C$*/included/normal/42/37/', reverse('special:inc-normal-view', kwargs={'arg1':42, 'arg2':37}))
  380
+        self.assertEqual('/+%5C$*/included/+%5C$*/', reverse('special:inc-special-view'))
362 381
 
363 382
 class RequestURLconfTests(TestCase):
364 383
     def setUp(self):

0 notes on commit b745fc0

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