[PATCH] hgweb: fixes broken URLs of RSS/Atom feeds (issue1772)
Yuya Nishihara
yuya at tcha.org
Tue Dec 1 09:38:28 CST 2009
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1259681737 -32400
# Node ID 259a5abc2a7288ca7db6ca4ca8edec2a30dd2b82
# Parent 2e67734e1453e44de0816c3f562005e89c09c21f
hgweb: fixes 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.
SCRIPT_NAME shouldn't contain `http://host:port' and ?query,
according to RFC 3875 4.1.13.
http://www.ietf.org/rfc/rfc3875
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -6,7 +6,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.
-import os, re, time
+import os, re, time, urlparse, urllib
from mercurial.i18n import _
from mercurial import ui, hg, util, templater
from mercurial import error, encoding
@@ -284,7 +284,8 @@ class hgwebdir(object):
self.refresh()
if self._baseurl is not None:
- req.env['SCRIPT_NAME'] = self._baseurl
+ path_part = urlparse.urlparse(self._baseurl)[2]
+ req.env['SCRIPT_NAME'] = urllib.unquote(path_part)
return tmpl("index", entries=entries, subdir=subdir,
sortcolumn=sortcolumn, descending=descending,
@@ -308,7 +309,8 @@ class hgwebdir(object):
return self.ui.config(section, name, default, untrusted)
if self._baseurl is not None:
- req.env['SCRIPT_NAME'] = self._baseurl
+ path_part = urlparse.urlparse(self._baseurl)[2]
+ req.env['SCRIPT_NAME'] = urllib.unquote(path_part)
url = req.env.get('SCRIPT_NAME', '')
if not url.endswith('/'):
diff --git a/tests/test-hgwebdir b/tests/test-hgwebdir
--- a/tests/test-hgwebdir
+++ b/tests/test-hgwebdir
@@ -51,6 +51,13 @@ echo % should succeed
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 '<link' | sed 's|//[.a-zA-Z0-9\-_]*:[0-9][0-9]*/|//example.com:8080/|'
+
+echo % rss-log without basedir
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/a/rss-log' \
+ | grep '<guid' | sed 's|//[.a-zA-Z0-9\-_]*:[0-9][0-9]*/|//example.com:8080/|'
cat > paths.conf <<EOF
[paths]
@@ -119,6 +126,28 @@ echo % collections: should succeed
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/b/file/tip/b?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/c/file/tip/c?style=raw'
+echo % atom-log with basedir /
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/atom-log' \
+ | grep '<link' | sed 's|//[.a-zA-Z0-9\-_]*:[0-9][0-9]*/|//example.com:8080/|'
+
+echo % rss-log with basedir /
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/rss-log' \
+ | grep '<guid' | sed 's|//[.a-zA-Z0-9\-_]*:[0-9][0-9]*/|//example.com:8080/|'
+
+"$TESTDIR/killdaemons.py"
+
+hg serve --config web.baseurl=http://hg.example.com:8080/foo/ -p $HGPORT2 -d \
+ --pid-file=hg.pid --webdir-conf collections.conf \
+ -A access-collections-2.log -E error-collections-2.log
+cat hg.pid >> $DAEMON_PIDS
+
+echo % atom-log with basedir /foo/
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/atom-log' \
+ | grep '<link' | sed 's|//[.a-zA-Z0-9\-_]*:[0-9][0-9]*/|//example.com:8080/|'
+
+echo % rss-log with basedir /foo/
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/rss-log' \
+ | grep '<guid' | sed 's|//[.a-zA-Z0-9\-_]*:[0-9][0-9]*/|//example.com:8080/|'
echo % paths errors 1
cat error-paths-1.log
@@ -128,3 +157,5 @@ echo % paths errors 3
cat error-paths-3.log
echo % collections errors
cat error-collections.log
+echo % collections errors 2
+cat error-collections-2.log
diff --git a/tests/test-hgwebdir.out b/tests/test-hgwebdir.out
--- a/tests/test-hgwebdir.out
+++ b/tests/test-hgwebdir.out
@@ -25,6 +25,12 @@ 404 Not Found
error: repository c not found
+% atom-log without basedir
+ <link rel="self" href="http://example.com:8080/a/atom-log"/>
+ <link rel="alternate" href="http://example.com:8080/a/"/>
+ <link href="http://example.com:8080/a/rev/8580ff50825a"/>
+% rss-log without basedir
+ <guid isPermaLink="true">http://example.com:8080/a/rev/8580ff50825a</guid>
% should succeed, slashy names
200 Script output follows
@@ -323,10 +329,10 @@ 200 Script output follows
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 @@ b
200 Script output follows
c
+% atom-log with basedir /
+ <link rel="self" href="http://example.com:8080/a/atom-log"/>
+ <link rel="alternate" href="http://example.com:8080/a/"/>
+ <link href="http://example.com:8080/a/rev/8580ff50825a"/>
+% rss-log with basedir /
+ <guid isPermaLink="true">http://example.com:8080/a/rev/8580ff50825a</guid>
+% atom-log with basedir /foo/
+ <link rel="self" href="http://example.com:8080/foo/a/atom-log"/>
+ <link rel="alternate" href="http://example.com:8080/foo/a/"/>
+ <link href="http://example.com:8080/foo/a/rev/8580ff50825a"/>
+% rss-log with basedir /foo/
+ <guid isPermaLink="true">http://example.com:8080/foo/a/rev/8580ff50825a</guid>
% paths errors 1
% paths errors 2
% paths errors 3
% collections errors
+% collections errors 2
More information about the Mercurial-devel
mailing list