changeset 3333:e6353b7b102a

NWI base URL detection fixes
author Brendan Cully <brendan@kublai.com>
date Tue, 10 Oct 2006 10:28:20 -0700
parents 34f08b8883cf
children 415905fad4fe
files mercurial/hgweb/hgweb_mod.py
diffstat 1 files changed, 19 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Tue Oct 10 11:47:19 2006 +0200
+++ b/mercurial/hgweb/hgweb_mod.py	Tue Oct 10 10:28:20 2006 -0700
@@ -647,38 +647,31 @@
                 def firstitem(query):
                     return query.split('&', 1)[0].split(';', 1)[0]
 
-                root = req.env.get('REQUEST_URI', '').split('?', 1)[0]
-                pi = req.env.get('PATH_INFO', '')
-                if pi:
-                    root = root[:-len(pi)]
-                
-                if req.env.has_key('REPO_NAME'):
-                    base = '/' + req.env['REPO_NAME']
-                else:
-                    base = root
+                def normurl(url):
+                    inner = '/'.join([x for x in url.split('/') if x])
+                    tl = len(url) > 1 and url.endswith('/') and '/' or ''
 
+                    return '%s%s%s' % (url.startswith('/') and '/' or '',
+                                       inner, tl)
+
+                root = normurl(req.env.get('REQUEST_URI', '').split('?', 1)[0])
+                pi = normurl(req.env.get('PATH_INFO', ''))
                 if pi:
-                    while pi.startswith('//'):
-                        pi = pi[1:]
-                    if pi.startswith(base):
-                        if len(pi) > len(base):
-                            base += '/'
-                            query = pi[len(base):]
-                        else:
-                            if req.env.has_key('REPO_NAME'):
-                                # We are using hgwebdir
-                                base += '/'
-                            else:
-                                base += '?'
-                            query = firstitem(req.env['QUERY_STRING'])
+                    # strip leading /
+                    pi = pi[1:]
+                    if pi:
+                        root = root[:-len(pi)]
+                    if req.env.has_key('REPO_NAME'):
+                        rn = req.env['REPO_NAME'] + '/'
+                        root += rn
+                        query = pi[len(rn):]
                     else:
-                        base += '/'
-                        query = pi[1:]
+                        query = pi
                 else:
-                    base += '?'
+                    root += '?'
                     query = firstitem(req.env['QUERY_STRING'])
 
-                return (root + base, query)
+                return (root, query)
 
             req.url, query = spliturl(req)