# HG changeset patch # User Yuya Nishihara # Date 1268234907 -32400 # Node ID 6d87c20cd7a8fb6eeb7343c952fda6fdc19539ea # Parent 9848b39a1472d60855a24c53d8a6bea9f9eecaba hgweb: fix broken URLs of RSS/Atom feeds (issue1772) This fixes doubled URL, e.g. http://example.orghttp://example.org/..., which appears on RSS/Atom feeds served by hgwebdir. It splits baseurl to update SERVER_NAME, SERVER_PORT and SCRIPT_NAME, according to RFC 3875. Updated the test output since SCRIPT_NAME becomes not to contain http://host:port part. diff -r 9848b39a1472 -r 6d87c20cd7a8 mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Thu Mar 11 00:25:46 2010 +0900 +++ b/mercurial/hgweb/hgwebdir_mod.py Thu Mar 11 00:28:27 2010 +0900 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -import os, re, time +import os, re, time, urlparse from mercurial.i18n import _ from mercurial import ui, hg, util, templater from mercurial import error, encoding @@ -339,5 +339,17 @@ return tmpl def updatereqenv(self, env): + def splitnetloc(netloc): + if ':' in netloc: + return netloc.split(':', 1) + else: + return (netloc, None) + if self._baseurl is not None: - env['SCRIPT_NAME'] = self._baseurl + urlcomp = urlparse.urlparse(self._baseurl) + host, port = splitnetloc(urlcomp[1]) + path = urlcomp[2] + env['SERVER_NAME'] = host + if port: + env['SERVER_PORT'] = port + env['SCRIPT_NAME'] = path diff -r 9848b39a1472 -r 6d87c20cd7a8 tests/test-hgwebdir --- a/tests/test-hgwebdir Thu Mar 11 00:25:46 2010 +0900 +++ b/tests/test-hgwebdir Thu Mar 11 00:28:27 2010 +0900 @@ -51,6 +51,13 @@ echo % should give a 404 - repo is not published "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/c/file/tip/c?style=raw' +echo % atom-log without basedir +"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/a/atom-log' \ + | grep ' paths.conf <> $DAEMON_PIDS + +echo % atom-log with basedir /foo/ +"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/atom-log' \ + | grep ' + + +% rss-log without basedir + http://example.com:8080/a/rev/8580ff50825a % should succeed, slashy names 200 Script output follows @@ -323,10 +329,10 @@ 200 Script output follows -http://hg.example.com:8080/a/ -http://hg.example.com:8080/a/.hg/patches/ -http://hg.example.com:8080/b/ -http://hg.example.com:8080/c/ +/a/ +/a/.hg/patches/ +/b/ +/c/ 200 Script output follows @@ -337,7 +343,20 @@ 200 Script output follows c +% atom-log with basedir / + + + +% rss-log with basedir / + http://example.com:8080/a/rev/8580ff50825a +% atom-log with basedir /foo/ + + + +% rss-log with basedir /foo/ + http://example.com:8080/foo/a/rev/8580ff50825a % paths errors 1 % paths errors 2 % paths errors 3 % collections errors +% collections errors 2