Skip to content
Myr

Raise BadRequest if static file name is invalid

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Raise BadRequest if static file name is invalid * Clean up syntax a bit * Remove unnecessary close()

authored by David Hou · committed by Markus Unterwaditzer · parent d3d8a46 · Browse files · 2 files+15 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−3 removed

  • tests:+9 added−0 removed
  • other:+6 added−3 removed

2 files+15 added−3 removed

modified:flask/helpers.py+6 added-3 removed
25 unmodified lines
26except ImportError:27 from urlparse import quote as url_quote2829from werkzeug.datastructures import Headers30from werkzeug.exceptions import NotFound30from werkzeug.exceptions import BadRequest, NotFound3132# this was moved in 0.733try:34 from werkzeug.wsgi import wrap_file
582 unmodified lines
617 """618 filename = safe_join(directory, filename)619 if not os.path.isabs(filename):620 filename = os.path.join(current_app.root_path, filename)621 try:621 if not os.path.isfile(filename):622 raise NotFound()622 if not os.path.isfile(filename):623 raise NotFound()624 except (TypeError, ValueError):625 raise BadRequest()626 options.setdefault('conditional', True)627 return send_file(filename, **options)628629
286 unmodified lines
modified:tests/test_helpers.py+9 added
13 unmodified lines
14import os15import datetime16import flask17from logging import StreamHandler18from werkzeug.exceptions import BadRequest19from werkzeug.http import parse_cache_control_header, parse_options_header20from werkzeug.http import http_date21from flask._compat import StringIO, text_type22
481 unmodified lines
504 rv.direct_passthrough = False505 assert rv.data.strip() == b'Hello Subdomain'506 rv.close()507508 def test_send_from_directory_bad_request(self):509 app = flask.Flask(__name__)510 app.testing = True511 app.root_path = os.path.join(os.path.dirname(__file__),512 'test_apps', 'subdomaintestmodule')513 with app.test_request_context():514 with pytest.raises(BadRequest):515 flask.send_from_directory('static', 'bad\x00')516517class TestLogging(object):518519 def test_logger_cache(self):
210 unmodified lines