mirror of
				https://github.com/django/django.git
				synced 2025-11-03 21:25:09 +00:00 
			
		
		
		
	Fixed #26812 -- Fixed APPEND_SLASH on a URL including querystring with a trailing slash.
This commit is contained in:
		
							parent
							
								
									29563cfb80
								
							
						
					
					
						commit
						f46a838efc
					
				
					 2 changed files with 13 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -74,7 +74,7 @@ class CommonMiddleware(MiddlewareMixin):
 | 
			
		|||
        Return True if settings.APPEND_SLASH is True and appending a slash to
 | 
			
		||||
        the request path turns an invalid path into a valid one.
 | 
			
		||||
        """
 | 
			
		||||
        if settings.APPEND_SLASH and not request.get_full_path().endswith('/'):
 | 
			
		||||
        if settings.APPEND_SLASH and not request.path_info.endswith('/'):
 | 
			
		||||
            urlconf = getattr(request, 'urlconf', None)
 | 
			
		||||
            return (
 | 
			
		||||
                not is_valid_path(request.path_info, urlconf) and
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,6 +83,18 @@ class CommonMiddlewareTest(SimpleTestCase):
 | 
			
		|||
        r = CommonMiddleware().process_response(request, response)
 | 
			
		||||
        self.assertEqual(r.url, '/slash/?test=1')
 | 
			
		||||
 | 
			
		||||
    @override_settings(APPEND_SLASH=True)
 | 
			
		||||
    def test_append_slash_redirect_querystring_have_slash(self):
 | 
			
		||||
        """
 | 
			
		||||
        APPEND_SLASH should append slash to path when redirecting a request
 | 
			
		||||
        with a querystring ending with slash.
 | 
			
		||||
        """
 | 
			
		||||
        request = self.rf.get('/slash?test=slash/')
 | 
			
		||||
        response = HttpResponseNotFound()
 | 
			
		||||
        r = CommonMiddleware().process_response(request, response)
 | 
			
		||||
        self.assertIsInstance(r, HttpResponsePermanentRedirect)
 | 
			
		||||
        self.assertEqual(r.url, '/slash/?test=slash/')
 | 
			
		||||
 | 
			
		||||
    @override_settings(APPEND_SLASH=True, DEBUG=True)
 | 
			
		||||
    def test_append_slash_no_redirect_on_POST_in_DEBUG(self):
 | 
			
		||||
        """
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue