Merge branch '0.10-maintenance'

This commit is contained in:
Armin Ronacher 2014-02-09 13:14:26 +00:00
commit 9298d89aed
3 changed files with 20 additions and 2 deletions

View file

@ -33,6 +33,8 @@ Version 0.10.2
the test client when absolute URLs were requested.
- Made `@before_first_request` into a decorator as intended.
- Fixed an etags bug when sending a file streams with a name.
- Fixed `send_from_directory` not expanding to the application root path
correctly.
Version 0.10.1
--------------

View file

@ -615,6 +615,8 @@ def send_from_directory(directory, filename, **options):
forwarded to :func:`send_file`.
"""
filename = safe_join(directory, filename)
if not os.path.isabs(filename):
filename = os.path.join(current_app.root_path, filename)
if not os.path.isfile(filename):
raise NotFound()
options.setdefault('conditional', True)

View file

@ -304,8 +304,11 @@ class SendfileTestCase(FlaskTestCase):
# etags
self.assert_equal(len(captured), 1)
with catch_warnings() as captured:
class PyStringIO(StringIO):
pass
class PyStringIO(object):
def __init__(self, *args, **kwargs):
self._io = StringIO(*args, **kwargs)
def __getattr__(self, name):
return getattr(self._io, name)
f = PyStringIO('Test')
f.name = 'test.txt'
rv = flask.send_file(f)
@ -407,6 +410,17 @@ class SendfileTestCase(FlaskTestCase):
self.assert_equal(cc.max_age, 10)
rv.close()
def test_send_from_directory(self):
app = flask.Flask(__name__)
app.testing = True
app.root_path = os.path.join(os.path.dirname(__file__),
'test_apps', 'subdomaintestmodule')
with app.test_request_context():
rv = flask.send_from_directory('static', 'hello.txt')
rv.direct_passthrough = False
self.assert_equal(rv.get_data().strip(), b'Hello Subdomain')
rv.close()
class LoggingTestCase(FlaskTestCase):