Changes between Initial Version and Version 1 of Ticket #12464


Ignore:
Timestamp:
Dec 29, 2009, 5:43:42 PM (14 years ago)
Author:
Ramiro Morales
Comment:

(reformatted description, please use the Preview button before submitting a ticket)

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12464 – Description

    initial v1  
    11Take the following Apache config snippet:
    22
     3{{{
    34RewriteEngine On
    45WSGIScriptAlias /project /django/project/bin/django.wsgi
     6}}}
    57
    68This results in mod_rewrite setting the SCRIPT_URL environment variable.
     
    810The code at http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/core/handlers/base.py#L204:
    911
     12{{{
    1013    script_url = environ.get('SCRIPT_URL', u'')
    1114    if not script_url:
     
    1417        return force_unicode(script_url[:-len(environ.get('PATH_INFO', ''))])
    1518    return force_unicode(environ.get('SCRIPT_NAME', u''))
     19}}}
    1620
    1721...behaves incorrectly when, in the above example, /project is requested from Apache.
     
    1923The problem is when PATH_INFO is empty, as it is in this case. Python
    2024has no notion of positive or negative zero (;-)) so we end up returning
    21 script_url[:0]. This results in request.META['SCRIPT_NAME'] being set to '', which in turn results in urls being generated incorrectly.
     25`script_url[:0]`. This results in `request.META['SCRIPT_NAME']`being set to `''`, which in turn results in urls being generated incorrectly.
    2226
    23 A workaround for this is to add the following rewrite rule before WSGIScriptAlias:
     27A workaround for this is to add the following rewrite rule before !WSGIScriptAlias:
    2428
     29{{{
    2530RewriteRule ^/project$ /project/ [R]
     31}}}
    2632
    2733This bug is potentially related to #9435, but this is ticket describes a real world problem that I believe has bitten more people than just me...
     
    2935A solution for this could well just be to change the section to:
    3036
     37{{{
    3138    if script_url:
    3239        path_info = environ.get('PATH_INFO', '')
     
    3542        return force_unicode(script_url)
    3643    return force_unicode(environ.get('SCRIPT_NAME', u''))
     44}}}
    3745
    3846...but I have no idea where to go about writing a test.
Back to Top