[PATCH 1 of 1] hgwebdir_mod.py can now handle 'baseurl' configurations with leading slash

wujek.srujek at googlemail.com wujek.srujek at googlemail.com
Mon Aug 1 05:03:26 CDT 2011


# HG changeset patch
# User wujek
# Date 1312184890 -7200
# Node ID 060a118fc62277c5cd71751503db19a7b4183a21
# Parent  cc2c22511707b13d045f17bb34e865d2393c53cf
hgwebdir_mod.py can now handle 'baseurl' configurations with leading slash

diff -r cc2c22511707 -r 060a118fc622 mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py	Fri Jul 29 17:27:38 2011 -0500
+++ b/mercurial/hgweb/hgwebdir_mod.py	Mon Aug 01 09:48:10 2011 +0200
@@ -370,4 +370,7 @@
             env['SERVER_NAME'] = u.host
             if u.port:
                 env['SERVER_PORT'] = u.port
-            env['SCRIPT_NAME'] = '/' + u.path
+            path = u.path
+            if not path.startswith('/'):
+                path = '/' + path
+            env['SCRIPT_NAME'] = path
diff -r cc2c22511707 -r 060a118fc622 tests/test-hgwebdir-baseurl.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-hgwebdir-baseurl.py	Mon Aug 01 09:48:10 2011 +0200
@@ -0,0 +1,22 @@
+from mercurial.hgweb.hgwebdir_mod import hgwebdir
+
+
+class hgwebdir_test(hgwebdir):
+
+    def __init__(self, baseurl):
+        self._baseurl = baseurl
+
+
+def test_baseurl(path, expected = None):
+    mock = hgwebdir_test(path)
+    env = {}
+    mock.updatereqenv(env)
+    if expected is None:
+        assert 'SCRIPT_NAME' not in env
+    else:
+        assert env['SCRIPT_NAME'] == expected
+
+
+test_baseurl('/hg', '/hg')
+test_baseurl('hg', '/hg')
+test_baseurl(None)


More information about the Mercurial-devel mailing list