File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed
Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1+ ### UNRELEASED
2+
3+ - Add a helper method to generate a gopher menu from a directory.
4+ - Fixed bug when redirecting to HTTP pages that was causing query parameters
5+ to get lost.
6+
17### v2.1.0 (2019-01-08)
28
39- Added support for establishing TLS connections with gopher clients. See the
Original file line number Diff line number Diff line change 2020from flask .helpers import safe_join , send_file
2121from flask .sessions import SecureCookieSessionInterface , SecureCookieSession
2222from werkzeug .local import LocalProxy
23- from werkzeug .urls import url_quote
2423from werkzeug .serving import WSGIRequestHandler , can_fork
2524from werkzeug .serving import BaseWSGIServer , ThreadingMixIn , ForkingMixIn
2625from werkzeug .serving import generate_adhoc_ssl_context , load_ssl_context
27-
2826from werkzeug .exceptions import HTTPException , BadRequest
27+ from jinja2 .filters import escape
2928from itsdangerous import URLSafeSerializer , BadSignature
3029
3130from .__version__ import __version__
@@ -433,7 +432,10 @@ def _add_gopher_url_redirect(self, app):
433432 """
434433 @app .route ('/URL:<path:url>' )
435434 def gopher_url_redirect (url ):
436- url = url_quote (url )
435+ # Use the full_path because it keeps any query params intact
436+ url = request .full_path .split (':' , 1 )[1 ] # Drop the "/URL:"
437+ url = url .rstrip ('?' ) # Flask adds an ? even if there are no params
438+ url = escape (url )
437439 return self .URL_REDIRECT_TEMPLATE .format (url = url ).strip ()
438440
439441 def _add_gopher_error_handler (self , app ):
Original file line number Diff line number Diff line change @@ -251,6 +251,19 @@ def test_url_redirect(self):
251251 href = b'<A HREF="https://gopher.floodgap.com">https://gopher.floodgap.com</A>'
252252 self .assertIn (href , resp )
253253
254+ def test_url_redirect_with_query_params (self ):
255+ """
256+ Selectors starting with URL:<path> should preserve the URL query params.
257+ """
258+ url = 'https://gopher.floodgap.com?foo=b"r&foz=baz'
259+ escaped_url = 'https://gopher.floodgap.com?foo=b"r&foz=baz'
260+
261+ resp = self .send_data ('/URL:{}\r \n ' .format (url ).encode ())
262+ self .assertTrue (resp .startswith (b'<HTML>' ))
263+ self .assertTrue (resp .endswith (b'</HTML>' ))
264+
265+ self .assertIn ('<A HREF="{0}">{0}</A>' .format (escaped_url ).encode (), resp )
266+
254267 def test_http_get (self ):
255268 """
256269 Regular HTTP requests should still work and headers should be passed
You can’t perform that action at this time.
0 commit comments