# HG changeset patch # User Brendan Cully # Date 2006-10-10 17:28:20 # Node ID e6353b7b102a323ba7a2d0052bd7be35a5fd0ce7 # Parent 34f08b8883cfce5e6a18e7a9a900feca773bd197 NWI base URL detection fixes diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -647,38 +647,31 @@ class hgweb(object): 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)