Skip to content
Myr

Fix ValueError for some invalid Range requests

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

fixes #2526

authored by ThiefMaster · committed by Adrian · parent f347d3c · Browse files · 3 files+30 added−2 removed
This commit

State

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

Diff stats

3 files+30 added−2 removed

  • tests:+20 added−1 removed
  • other:+10 added−1 removed

3 files+30 added−2 removed

modified:flask/helpers.py+2 added-1 removed
589 unmodified lines
590 try:591 rv = rv.make_conditional(request, accept_ranges=True,592 complete_length=fsize)593 except RequestedRangeNotSatisfiable:594 if file is not None:594 file.close()595 file.close()596 raise597 else:598 rv = rv.make_conditional(request)599 # make sure we don't send x-sendfile for servers that
368 unmodified lines
modified:tests/test_helpers.py+20 added-1 removed
466 unmodified lines
467 rv.close()468469 @pytest.mark.skipif(470 not callable(getattr(Range, 'to_content_range_header', None)),471 reason="not implement within werkzeug"471 reason="not implemented within werkzeug"472 )473 def test_send_file_range_request(self):474 app = flask.Flask(__name__)475
52 unmodified lines
528 datetime.datetime(1999, 1, 1))})529 assert rv.status_code == 200530 rv.close()531532 @pytest.mark.skipif(533 not callable(getattr(Range, 'to_content_range_header', None)),534 reason="not implemented within werkzeug"535 )536 def test_send_file_range_request_xsendfile_invalid(self):537 # https://github.com/pallets/flask/issues/2526538 app = flask.Flask(__name__)539 app.use_x_sendfile = True540541 @app.route('/')542 def index():543 return flask.send_file('static/index.html', conditional=True)544545 c = app.test_client()546547 rv = c.get('/', headers={'Range': 'bytes=1000-'})548 assert rv.status_code == 416549 rv.close()550551 def test_attachment(self):552 app = flask.Flask(__name__)553 with app.test_request_context():554 with open(os.path.join(app.root_path, 'static/index.html')) as f:
351 unmodified lines
modified:CHANGES+8 added
13 unmodified lines
14- Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify()15 method returns compressed response by default, and pretty response in16 debug mode.1718Version 0.12.319--------------2021Bugfix release, unreleased2223- Fix a ValueError caused by invalid Range requests in some cases242526Version 0.12.227--------------2829Released on May 16 2017
612 unmodified lines