diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -747,7 +747,11 @@ def stylemap(styles, paths=None): styles = [styles] for style in styles: - if not style: + # only plain name is allowed to honor template paths + if (not style + or style in (os.curdir, os.pardir) + or os.sep in style + or os.altsep and os.altsep in style): continue locations = [os.path.join(style, 'map'), 'map-' + style] locations.append('map') diff --git a/tests/test-hgweb.t b/tests/test-hgweb.t --- a/tests/test-hgweb.t +++ b/tests/test-hgweb.t @@ -578,6 +578,45 @@ phase changes are refreshed (issue4061) +no style can be loaded from directories other than the specified paths + + $ mkdir -p x/templates/fallback + $ cat < x/templates/fallback/map + > default = 'shortlog' + > shortlog = 'fall back to default\n' + > mimetype = 'text/plain' + > EOF + $ cat < x/map + > default = 'shortlog' + > shortlog = 'access to outside of templates directory\n' + > mimetype = 'text/plain' + > EOF + + $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS + $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log \ + > --config web.style=fallback --config web.templates=x/templates + $ cat hg.pid >> $DAEMON_PIDS + + $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT "?style=`pwd`/x" + 200 Script output follows + + fall back to default + + $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '?style=..' + 200 Script output follows + + fall back to default + + $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '?style=./..' + 200 Script output follows + + fall back to default + + $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '?style=.../.../' + 200 Script output follows + + fall back to default + errors $ cat errors.log