Ticket #12464: 12464.patch

File 12464.patch, 2.2 KB (added by Greg Wogan-Browne, 14 years ago)

Patch against revision 13959

  • django/core/handlers/base.py

     
    215215    if not script_url:
    216216        script_url = environ.get('REDIRECT_URL', u'')
    217217    if script_url:
    218         return force_unicode(script_url[:-len(environ.get('PATH_INFO', ''))])
     218        path_info = environ.get('PATH_INFO', u'')
     219        if path_info:
     220            script_url = script_url[:-len(path_info)]
     221        return force_unicode(script_url)
    219222    return force_unicode(environ.get('SCRIPT_NAME', u''))
    220223
  • tests/regressiontests/requests/tests.py

     
    33import unittest
    44
    55from django.http import HttpRequest, HttpResponse, parse_cookie
     6from django.core.handlers.base import get_script_name
    67from django.core.handlers.wsgi import WSGIRequest
    78from django.core.handlers.modpython import ModPythonRequest
    89from django.utils.http import cookie_date
     10from django.conf import settings
    911
    1012class RequestsTests(unittest.TestCase):
    1113
     
    4547        self.assertEqual(request.COOKIES.keys(), [])
    4648        self.assertEqual(request.META.keys(), [])
    4749
     50    def test_get_script_name(self):
     51        'get_script_name is computing the script name correctly'
     52        old = getattr(settings,'FORCE_SCRIPT_NAME',None)
     53        if old:
     54            settings.FORCE_SCRIPT_NAME = None
     55        self.assertEqual(get_script_name({'PATH_INFO': u'', 'SCRIPT_URL': u'test'}), u'test')
     56        self.assertEqual(get_script_name({'PATH_INFO': u'/path', 'SCRIPT_URL': u'test/path'}), u'test')
     57        self.assertEqual(get_script_name({'PATH_INFO': u'/path', 'REDIRECT_URL': u'test/path'}), u'test')
     58        self.assertEqual(get_script_name({'SCRIPT_NAME': u'test'}), u'test')
     59        settings.FORCE_SCRIPT_NAME = u'forced'
     60        self.assertEqual(get_script_name({'SCRIPT_NAME': u'test'}), u'forced')
     61        settings.FORCE_SCRIPT_NAME = old
     62
    4863    def test_parse_cookie(self):
    4964        self.assertEqual(parse_cookie('invalid:key=true'), {})
    5065
Back to Top