When redirecting, ignore querystring part (after ?) of URL
authorMagnus Hagander <magnus@hagander.net>
Tue, 13 Jun 2017 12:55:30 +0000 (14:55 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 13 Jun 2017 12:55:30 +0000 (14:55 +0200)
This can sometimes be added by some broken trackers, but we can safely
ignore it completely.

Reported by Stefan Kaltenbrunner

redirector/redirector.py

index 7f918f8b4e945e44e7e27883ad37b0a2ccb6be3d..27f15f006b7b843a92c56ca966614a2374a46bd1 100755 (executable)
@@ -26,8 +26,15 @@ def iddecode(idstr):
 
 def application(environ, start_response):
        try:
+               # If we have a querystring, get rid of it. This can (presumably)
+               # happen with some click-tracking systems.
+               if '?' in environ['REQUEST_URI']:
+                       uri = environ['REQUEST_URI'].split('?')[0]
+               else:
+                       uri = environ['REQUEST_URI']
+
                # Start by getting the id from the request
-               id = iddecode(environ['REQUEST_URI'].split('/')[-1])
+               id = iddecode(uri.split('/')[-1])
 
                # Let's figure out where this URL should be