Skip to content

Commit

Permalink
Merge branch '0.10-maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 9, 2014
2 parents 23d9b33 + 964c4a3 commit 9298d89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------
Expand Down
2 changes: 2 additions & 0 deletions flask/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ def download_file(filename):
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)
Expand Down
18 changes: 16 additions & 2 deletions flask/testsuite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,11 @@ def test_send_file_object(self):
# 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)
Expand Down Expand Up @@ -407,6 +410,17 @@ def get_send_file_max_age(self, filename):
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):

Expand Down

0 comments on commit 9298d89

Please sign in to comment.