mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[2.0.x] Fixed #28947 -- Fixed crash when coercing a translatable URL pattern to str.
Regression indf41b5a05d. Backport of01384ce36cfrom master
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							6f86d8bc69
						
					
				
				
					commit
					c99ab335a1
				
			| @@ -183,7 +183,7 @@ class RegexPattern(CheckURLMixin): | |||||||
|             ) |             ) | ||||||
|  |  | ||||||
|     def __str__(self): |     def __str__(self): | ||||||
|         return self._regex |         return str(self._regex) | ||||||
|  |  | ||||||
|  |  | ||||||
| _PATH_PARAMETER_COMPONENT_RE = re.compile( | _PATH_PARAMETER_COMPONENT_RE = re.compile( | ||||||
| @@ -271,7 +271,7 @@ class RoutePattern(CheckURLMixin): | |||||||
|         return re.compile(_route_to_regex(route, self._is_endpoint)[0]) |         return re.compile(_route_to_regex(route, self._is_endpoint)[0]) | ||||||
|  |  | ||||||
|     def __str__(self): |     def __str__(self): | ||||||
|         return self._route |         return str(self._route) | ||||||
|  |  | ||||||
|  |  | ||||||
| class LocalePrefixPattern: | class LocalePrefixPattern: | ||||||
|   | |||||||
| @@ -31,3 +31,6 @@ Bugfixes | |||||||
|   trailing zeros in the fractional part truncated (:ticket:`28915`). |   trailing zeros in the fractional part truncated (:ticket:`28915`). | ||||||
|  |  | ||||||
| * Fixed crash in the ``testserver`` command startup (:ticket:`28941`). | * Fixed crash in the ``testserver`` command startup (:ticket:`28941`). | ||||||
|  |  | ||||||
|  | * Fixed crash when coercing a translatable URL pattern to ``str`` | ||||||
|  |   (:ticket:`28947`). | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								tests/urlpatterns/test_resolvers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								tests/urlpatterns/test_resolvers.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | from django.test import SimpleTestCase | ||||||
|  | from django.urls.resolvers import RegexPattern, RoutePattern | ||||||
|  | from django.utils.translation import gettext_lazy as _ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class RegexPatternTests(SimpleTestCase): | ||||||
|  |  | ||||||
|  |     def test_str(self): | ||||||
|  |         self.assertEqual(str(RegexPattern(_('^translated/$'))), '^translated/$') | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class RoutePatternTests(SimpleTestCase): | ||||||
|  |  | ||||||
|  |     def test_str(self): | ||||||
|  |         self.assertEqual(str(RoutePattern(_('translated/'))), 'translated/') | ||||||
		Reference in New Issue
	
	Block a user