Skip to content
Myr

Merge pull request #1813 from pallets/bugfix/scheme

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

Resolve state issue for url_for with forced scheme

authored by Armin Ronacher · committed by Armin Ronacher · parents 87787b1, 6aee9f6 · Browse files · 2 files+21 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

2 files+21 added−2 removed

  • tests:+10 added−0 removed
  • other:+11 added−2 removed

2 files+21 added−2 removed

modified:flask/helpers.py+11 added-2 removed
304 unmodified lines
305 method = values.pop('_method', None)306 scheme = values.pop('_scheme', None)307 appctx.app.inject_url_defaults(endpoint, values)308309 # This is not the best way to deal with this but currently the310 # underlying Werkzeug router does not support overriding the scheme on311 # a per build call basis.312 old_scheme = None313 if scheme is not None:314 if not external:315 raise ValueError('When specifying _scheme, _external must be True')316 old_scheme = url_adapter.url_scheme317 url_adapter.url_scheme = scheme318319 try:320 try:315 rv = url_adapter.build(endpoint, values, method=method,316 force_external=external)321 rv = url_adapter.build(endpoint, values, method=method,322 force_external=external)323 finally:324 if old_scheme is not None:325 url_adapter.url_scheme = old_scheme326 except BuildError as error:327 # We need to inject the values again so that the app callback can328 # deal with that sort of stuff.329 values['_external'] = external
601 unmodified lines
modified:tests/test_helpers.py+10 added
625 unmodified lines
626 flask.url_for,627 'index',628 _scheme='https')629630 def test_url_for_with_alternating_schemes(self):631 app = flask.Flask(__name__)632 @app.route('/')633 def index():634 return '42'635 with app.test_request_context():636 assert flask.url_for('index', _external=True) == 'http://localhost/'637 assert flask.url_for('index', _external=True, _scheme='https') == 'https://localhost/'638 assert flask.url_for('index', _external=True) == 'http://localhost/'639640 def test_url_with_method(self):641 from flask.views import MethodView642 app = flask.Flask(__name__)643 class MyView(MethodView):
96 unmodified lines