From e5a2980d1ba36e0f4af0af65fb09b22055e0d5be Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 1 Aug 2022 20:03:29 +0200 Subject: [PATCH] normalizing request.full_path --- files/__main__.py | 3 ++- files/routes/comments.py | 4 ++-- files/routes/front.py | 4 ++-- files/routes/posts.py | 4 ++-- files/routes/static.py | 4 ++-- files/routes/users.py | 8 ++++---- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 6b46c468b..dedc1c872 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -96,7 +96,8 @@ def before_request(): g.webview = '; wv) ' in ua g.inferior_browser = 'iphone' in ua or 'ipad' in ua or 'ipod' in ua or 'mac os' in ua or ' firefox/' in ua - request.path = request.path.rstrip("/") + request.path = request.path.rstrip('/') + request.full_path = request.full_path.rstrip('?').rstrip('/') @app.after_request def after_request(response): diff --git a/files/routes/comments.py b/files/routes/comments.py index 44e743b8c..e8cdbb123 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -37,8 +37,8 @@ WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"} @auth_desired def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): - if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path.rstrip('?')}#context") - if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','').rstrip('?') + '#context') + if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}#context") + if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','') + '#context') try: cid = int(cid) except: abort(404) diff --git a/files/routes/front.py b/files/routes/front.py index 1723e1eac..f8768e16d 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -20,12 +20,12 @@ from files.helpers.awards import award_timers def front_all(v, sub=None, subdomain=None): if not v and not request.path.startswith('/logged_out'): - return redirect(f"/logged_out{request.full_path.rstrip('?')}") + return redirect(f"/logged_out{request.full_path}") if v and v.is_banned and not v.unban_utc: return redirect('https://deuxrama.net') if v and request.path.startswith('/logged_out'): - return redirect(request.full_path.replace('/logged_out','/').rstrip('?')) + return redirect(request.full_path.replace('/logged_out','/')) if sub: sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() diff --git a/files/routes/posts.py b/files/routes/posts.py index c1fbeccde..38079c260 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -106,8 +106,8 @@ def submit_get(v, sub=None): @auth_desired def post_id(pid, anything=None, v=None, sub=None): - if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path.rstrip('?')}") - if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','').rstrip('?')) + if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}") + if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','')) try: pid = int(pid) except Exception as e: pass diff --git a/files/routes/static.py b/files/routes/static.py index d2c38876e..244f1ef5e 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -59,8 +59,8 @@ def marsey_list(): @app.get('/logged_out/sidebar') @auth_desired def sidebar(v): - if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path.rstrip('?')}") - if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','').rstrip('?')) + if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}") + if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','')) return render_template('sidebar.html', v=v) diff --git a/files/routes/users.py b/files/routes/users.py index 71a5493f5..fd2e06c93 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -908,10 +908,10 @@ def visitors(v): def u_username(username, v=None): if not v and not request.path.startswith('/logged_out'): - return redirect(f"/logged_out{request.full_path.rstrip('?')}") + return redirect(f"/logged_out{request.full_path}") if v and request.path.startswith('/logged_out'): - return redirect(request.full_path.replace('/logged_out','').rstrip('?')) + return redirect(request.full_path.replace('/logged_out','')) u = get_user(username, v=v, rendered=True) @@ -1020,10 +1020,10 @@ def u_username(username, v=None): def u_username_comments(username, v=None): if not v and not request.path.startswith('/logged_out'): - return redirect(f"/logged_out{request.full_path.rstrip('?')}") + return redirect(f"/logged_out{request.full_path}") if v and request.path.startswith('/logged_out'): - return redirect(request.full_path.replace('/logged_out','').rstrip('?')) + return redirect(request.full_path.replace('/logged_out','')) user = get_user(username, v=v, rendered=True)