Fixed #23173 -- Fixed incorrect stripping of SCRIPT_URL
This commit is contained in:
parent
a5b225084f
commit
336512fae7
|
@ -219,7 +219,7 @@ def get_script_name(environ):
|
||||||
|
|
||||||
if script_url:
|
if script_url:
|
||||||
path_info = get_bytes_from_wsgi(environ, 'PATH_INFO', '')
|
path_info = get_bytes_from_wsgi(environ, 'PATH_INFO', '')
|
||||||
script_name = script_url[:-len(path_info)]
|
script_name = script_url[:-len(path_info)] if path_info else script_url
|
||||||
else:
|
else:
|
||||||
script_name = get_bytes_from_wsgi(environ, 'SCRIPT_NAME', '')
|
script_name = get_bytes_from_wsgi(environ, 'SCRIPT_NAME', '')
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.handlers.wsgi import WSGIHandler, WSGIRequest
|
from django.core.handlers.wsgi import WSGIHandler, WSGIRequest, get_script_name
|
||||||
from django.core.signals import request_finished, request_started
|
from django.core.signals import request_finished, request_started
|
||||||
from django.db import close_old_connections, connection
|
from django.db import close_old_connections, connection
|
||||||
from django.test import (
|
from django.test import (
|
||||||
|
@ -200,3 +200,14 @@ class HandlerNotFoundTest(TestCase):
|
||||||
def test_environ_path_info_type(self):
|
def test_environ_path_info_type(self):
|
||||||
environ = RequestFactory().get('/%E2%A8%87%87%A5%E2%A8%A0').environ
|
environ = RequestFactory().get('/%E2%A8%87%87%A5%E2%A8%A0').environ
|
||||||
self.assertIsInstance(environ['PATH_INFO'], six.text_type)
|
self.assertIsInstance(environ['PATH_INFO'], six.text_type)
|
||||||
|
|
||||||
|
|
||||||
|
class ScriptNameTests(TestCase):
|
||||||
|
def test_get_script_name(self):
|
||||||
|
# Regression test for #23173
|
||||||
|
# Test first without PATH_INFO
|
||||||
|
script_name = get_script_name({'SCRIPT_URL': '/foobar/'})
|
||||||
|
self.assertEqual(script_name, '/foobar/')
|
||||||
|
|
||||||
|
script_name = get_script_name({'SCRIPT_URL': '/foobar/', 'PATH_INFO': '/'})
|
||||||
|
self.assertEqual(script_name, '/foobar')
|
||||||
|
|
Loading…
Reference in New Issue