diff --git a/CHANGES b/CHANGES index fbf86829..b19db94c 100644 --- a/CHANGES +++ b/CHANGES @@ -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 -------------- diff --git a/flask/helpers.py b/flask/helpers.py index 90c2d473..7d688c61 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -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) diff --git a/flask/testsuite/helpers.py b/flask/testsuite/helpers.py index 549f67fa..7a5600ed 100644 --- a/flask/testsuite/helpers.py +++ b/flask/testsuite/helpers.py @@ -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):