Skip to content

Commit e04483b

Browse files
committed
normpath is now used before loading templates
1 parent 4927ce2 commit e04483b

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Bugfix release, release date to be announced.
1010

1111
- Fixed an issue where the default `OPTIONS` response was
1212
not exposing all valid methods in the `Allow` header.
13+
- Jinja2 template loading syntax now allows "./" in front of
14+
a template load path. Previously this caused issues with
15+
module setups.
1316

1417
Version 0.6
1518
-----------

flask/templating.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:copyright: (c) 2010 by Armin Ronacher.
99
:license: BSD, see LICENSE for more details.
1010
"""
11+
import posixpath
1112
from jinja2 import BaseLoader, TemplateNotFound
1213

1314
from .globals import _request_ctx_stack
@@ -36,6 +37,9 @@ def __init__(self, app):
3637
self.app = app
3738

3839
def get_source(self, environment, template):
40+
template = posixpath.normpath(template)
41+
if template.startswith('../'):
42+
raise TemplateNotFound(template)
3943
loader = None
4044
try:
4145
module, name = template.split('/', 1)

tests/flask_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ def test_templates_and_static(self):
767767
assert rv.data == 'Hello from the Frontend'
768768
rv = c.get('/admin/')
769769
assert rv.data == 'Hello from the Admin'
770+
rv = c.get('/admin/index2')
771+
assert rv.data == 'Hello from the Admin'
770772
rv = c.get('/admin/static/test.txt')
771773
assert rv.data.strip() == 'Admin File'
772774
rv = c.get('/admin/static/css/test.css')

tests/moduleapp/apps/admin/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
77
@admin.route('/')
88
def index():
99
return render_template('admin/index.html')
10+
11+
12+
@admin.route('/index2')
13+
def index2():
14+
return render_template('./admin/index.html')

0 commit comments

Comments
 (0)