mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[1.10.x] Fixed #27238 -- Disabled check_pattern_startswith_slash if settings.APPEND_SLASH=False.
Thanks strycore for the report and timgraham for suggesting the
solution.
Backport of 911d9f4ed1 from master
			
			
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							9c3f864305
						
					
				
				
					commit
					190cd0e49f
				
			| @@ -95,6 +95,10 @@ def check_pattern_startswith_slash(pattern): | |||||||
|     Check that the pattern does not begin with a forward slash. |     Check that the pattern does not begin with a forward slash. | ||||||
|     """ |     """ | ||||||
|     regex_pattern = pattern.regex.pattern |     regex_pattern = pattern.regex.pattern | ||||||
|  |     if not settings.APPEND_SLASH: | ||||||
|  |         # Skip check as it can be useful to start a URL pattern with a slash | ||||||
|  |         # when APPEND_SLASH=False. | ||||||
|  |         return [] | ||||||
|     if regex_pattern.startswith('/') or regex_pattern.startswith('^/'): |     if regex_pattern.startswith('/') or regex_pattern.startswith('^/'): | ||||||
|         warning = Warning( |         warning = Warning( | ||||||
|             "Your URL pattern {} has a regex beginning with a '/'. Remove this " |             "Your URL pattern {} has a regex beginning with a '/'. Remove this " | ||||||
|   | |||||||
| @@ -14,3 +14,6 @@ Bugfixes | |||||||
|  |  | ||||||
| * Allowed combining ``contrib.postgres.search.SearchQuery`` with more than one | * Allowed combining ``contrib.postgres.search.SearchQuery`` with more than one | ||||||
|   ``&`` or ``|`` operators (:ticket:`27143`). |   ``&`` or ``|`` operators (:ticket:`27143`). | ||||||
|  |  | ||||||
|  | * Disabled system check for URL patterns beginning with a '/' when | ||||||
|  |   ``APPEND_SLASH=False`` (:ticket:`27238`). | ||||||
|   | |||||||
| @@ -55,6 +55,16 @@ class CheckUrlsTest(SimpleTestCase): | |||||||
|  |  | ||||||
|         self.assertIn(expected_msg, warning.msg) |         self.assertIn(expected_msg, warning.msg) | ||||||
|  |  | ||||||
|  |     @override_settings( | ||||||
|  |         ROOT_URLCONF='check_framework.urls.beginning_with_slash', | ||||||
|  |         APPEND_SLASH=False, | ||||||
|  |     ) | ||||||
|  |     def test_beginning_with_slash_append_slash(self): | ||||||
|  |         # It can be useful to start a URL pattern with a slash when | ||||||
|  |         # APPEND_SLASH=False (#27238). | ||||||
|  |         result = check_url_config(None) | ||||||
|  |         self.assertEqual(result, []) | ||||||
|  |  | ||||||
|     @override_settings(ROOT_URLCONF='check_framework.urls.name_with_colon') |     @override_settings(ROOT_URLCONF='check_framework.urls.name_with_colon') | ||||||
|     def test_name_with_colon(self): |     def test_name_with_colon(self): | ||||||
|         result = check_url_config(None) |         result = check_url_config(None) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user