durusmail: qp: Publisher.complete_url(), and running behind a script
Publisher.complete_url(), and running behind a script
2007-01-24
2007-01-24
2007-01-25
Publisher.complete_url(), and running behind a script
mario ruggier
2007-01-24
Hi,

stumbled onto this issue on a site running behind a cgi script instead
of mod_scgi.

Given my url path is something like "/app.cgi/component",
then doing publisher.redirect("/app.cgi/component")
will send to the location "/app.cgi/app.cgi/component".

The problem is in how the complete_url() is calculated...

I have come across the inverse of this issue, and I now make systematic
use of this utility function when I want to make sure that the url
paths (e.g. for js, css, etc...) are properly script_named:

def script_name_path (path):
     ''' (path:str) -> str
     Returns script_name-normalized path.
     '''
     if path is None:
         raise ValueError, 'Path cannot be None.'
     script_name = get_request().get_script_name()
     if not (-1 < path.find(script_name) <= 1):
         # path is not yet "script_named"
         if script_name:
             if not path.startswith('/'):
                 path = '/' + path
             path = script_name + path
     # Isn't script_name always starting with a "/" ? Can anyone confirm?
     if not path.startswith('/'):
         path = '/' + path
     return path

It seems to me you need to make complete_url() do some sort of opposite
test than this, i.e. the check:

         if s.startswith('/'):
             complete_path = get_request().get_script_name() + s

should also check if s is already script_named ?

mario

reply