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
+
1
7
### v2.1.0 (2019-01-08)
2
8
3
9
- Added support for establishing TLS connections with gopher clients. See the
Original file line number Diff line number Diff line change 20
20
from flask .helpers import safe_join , send_file
21
21
from flask .sessions import SecureCookieSessionInterface , SecureCookieSession
22
22
from werkzeug .local import LocalProxy
23
- from werkzeug .urls import url_quote
24
23
from werkzeug .serving import WSGIRequestHandler , can_fork
25
24
from werkzeug .serving import BaseWSGIServer , ThreadingMixIn , ForkingMixIn
26
25
from werkzeug .serving import generate_adhoc_ssl_context , load_ssl_context
27
-
28
26
from werkzeug .exceptions import HTTPException , BadRequest
27
+ from jinja2 .filters import escape
29
28
from itsdangerous import URLSafeSerializer , BadSignature
30
29
31
30
from .__version__ import __version__
@@ -433,7 +432,10 @@ def _add_gopher_url_redirect(self, app):
433
432
"""
434
433
@app .route ('/URL:<path:url>' )
435
434
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 )
437
439
return self .URL_REDIRECT_TEMPLATE .format (url = url ).strip ()
438
440
439
441
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):
251
251
href = b'<A HREF="https://gopher.floodgap.com">https://gopher.floodgap.com</A>'
252
252
self .assertIn (href , resp )
253
253
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
+
254
267
def test_http_get (self ):
255
268
"""
256
269
Regular HTTP requests should still work and headers should be passed
You can’t perform that action at this time.
0 commit comments