Skip to content

Commit a3a8439

Browse files
committed
normpath is now used before loading templates
1 parent 38107c7 commit a3a8439

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
@@ -25,6 +25,9 @@ Bugfix release, release date to be announced.
2525

2626
- Fixed an issue where the default `OPTIONS` response was
2727
not exposing all valid methods in the `Allow` header.
28+
- Jinja2 template loading syntax now allows "./" in front of
29+
a template load path. Previously this caused issues with
30+
module setups.
2831

2932
Version 0.6
3033
-----------

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
@@ -789,6 +789,8 @@ def test_templates_and_static(self):
789789
assert rv.data == 'Hello from the Frontend'
790790
rv = c.get('/admin/')
791791
assert rv.data == 'Hello from the Admin'
792+
rv = c.get('/admin/index2')
793+
assert rv.data == 'Hello from the Admin'
792794
rv = c.get('/admin/static/test.txt')
793795
assert rv.data.strip() == 'Admin File'
794796
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)