diff options
author | Marcel Hellkamp <marc@gsites.de> | 2012-10-17 21:05:35 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2012-10-17 22:40:59 +0200 |
commit | 698d1830be1491684ab77c546297667e01fd61c8 (patch) | |
tree | c1b7cb5bb618a401d25ef9fae6111a070ec7154f | |
parent | 8048b8c0d1d81d2049a7e92ed4303819a310895d (diff) | |
download | bottle-698d1830be1491684ab77c546297667e01fd61c8.tar.gz |
Fix #387: Template lookup found files in workdir, even if TEMPLATE_PATH did not contain '.'.
The template path list is now obeyed (with an exception for templates with an explicit absolute path).
The next release will tighten the rules a bit further: TEMPLATE_PATH must not be empty, and absolute paths are
considered relative, too. This ensures that only templates from within TEMPLATE_PATH directries are loaded.
-rw-r--r-- | bottle.py | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -2799,11 +2799,19 @@ class BaseTemplate(object): def search(cls, name, lookup=[]): """ Search name in all directories specified in lookup. First without, then with common extensions. Return first hit. """ - if os.path.isfile(name): return name + if not lookup: + depr('The template lookup path list should not be empty.') + lookup = ['.'] + + if os.path.isabs(name) and os.path.isfile(name): + depr('Absolute template path names are deprecated.') + return os.path.abspath(name) + for spath in lookup: - fname = os.path.join(spath, name) - if os.path.isfile(fname): - return fname + spath = os.path.abspath(spath) + os.sep + fname = os.path.abspath(os.path.join(spath, name)) + if not fname.startswith(spath): continue + if os.path.isfile(fname): return fname for ext in cls.extensions: if os.path.isfile('%s.%s' % (fname, ext)): return '%s.%s' % (fname, ext) |