From 6e9d3d68dc6aa17a4b6112b373a3959d19adbfaa Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 30 Jul 2023 09:20:02 +0300 Subject: [PATCH] strip after not before --- files/helpers/actions.py | 2 +- files/routes/admin.py | 6 +++--- files/routes/comments.py | 4 ++-- files/routes/posts.py | 4 ++-- files/routes/settings.py | 4 ++-- files/routes/subs.py | 2 +- files/routes/users.py | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 0e92c06a6..2c0895c71 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -194,7 +194,7 @@ def execute_snappy(post, v): body += addition archive_url(href) - body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT] + body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() body_html = sanitize(body, snappy=True, showmore=True) if len(body_html) == 0: diff --git a/files/routes/admin.py b/files/routes/admin.py index 89dea8458..ec359e691 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -845,7 +845,7 @@ def shadowban(user_id, v): if user.admin_level > v.admin_level: abort(403) user.shadowbanned = v.id - reason = request.values.get("reason", "").strip()[:256] + reason = request.values.get("reason", "")[:256].strip() if not reason: abort(400, "You need to submit a reason for shadowbanning!") @@ -910,7 +910,7 @@ def admin_title_change(user_id, v): user = get_account(user_id) - new_name=request.values.get("title").strip()[:256] + new_name=request.values.get("title")[:256].strip() user.customtitleplain=new_name new_name = filter_emojis_only(new_name) @@ -982,7 +982,7 @@ def ban_user(fullname, v): if days < 0: abort(400, "You can't bans people for negative days!") - reason = request.values.get("reason", "").strip()[:256] + reason = request.values.get("reason", "")[:256].strip() if not reason: abort(400, "You need to submit a reason for banning!") diff --git a/files/routes/comments.py b/files/routes/comments.py index 0bbff8247..d9a56dd71 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -229,7 +229,7 @@ def comment(v): abort(415) body = body.replace('\n ', '\n').replace('\r', '') - body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT].strip() + body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and posting_to_post and post_target.id == SNAPPY_THREAD and level == 1: with open(f"snappy_{SITE_NAME}.txt", "r+", encoding="utf-8") as f: @@ -631,7 +631,7 @@ def edit_comment(cid, v): execute_antispam_comment_check(body, v) body = process_files(request.files, v, body) - body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT] # process_files potentially adds characters to the post + body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() # process_files potentially adds characters to the post body_for_sanitize = body if v.owoify: diff --git a/files/routes/posts.py b/files/routes/posts.py index a8a6d8186..f42f309f8 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -564,7 +564,7 @@ def submit_post(v, sub=None): abort(400, "There's a 2048 character limit for URLs!") body = process_files(request.files, v, body) - body = body.strip()[:POST_BODY_LENGTH_LIMIT(v)] # process_files() adds content to the body, so we need to re-strip + body = body[:POST_BODY_LENGTH_LIMIT(v)].strip() # process_files() adds content to the body, so we need to re-strip body_html = sanitize(body, count_emojis=True, limit_pings=100) @@ -1060,7 +1060,7 @@ def edit_post(pid, v): p.title_html = title_html body = process_files(request.files, v, body) - body = body.strip()[:POST_BODY_LENGTH_LIMIT(v)] # process_files() may be adding stuff to the body + body = body[:POST_BODY_LENGTH_LIMIT(v)].strip() # process_files() may be adding stuff to the body if body != p.body: body_html = sanitize(body, golden=False, limit_pings=100) diff --git a/files/routes/settings.py b/files/routes/settings.py index 3be1eee84..0105303c5 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -623,7 +623,7 @@ def settings_css_get(v): @auth_required def settings_css(v): if v.chud: abort(400, "Chuded users can't edit CSS!") - css = request.values.get("css", v.css).strip().replace('\\', '').strip()[:CSS_LENGTH_LIMIT] + css = request.values.get("css", v.css).strip().replace('\\', '')[:CSS_LENGTH_LIMIT].strip() v.css = css g.db.add(v) @@ -636,7 +636,7 @@ def settings_css(v): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required def settings_profilecss(v): - profilecss = request.values.get("profilecss", v.profilecss).strip().replace('\\', '').strip()[:CSS_LENGTH_LIMIT] + profilecss = request.values.get("profilecss", v.profilecss).replace('\\', '')[:CSS_LENGTH_LIMIT].strip() valid, error = validate_css(profilecss) if not valid: return render_template("settings/css.html", error=error, v=v, profilecss=profilecss) diff --git a/files/routes/subs.py b/files/routes/subs.py index bdd135132..ecb051d21 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -454,7 +454,7 @@ def post_sub_sidebar(v, sub): if not v.mods(sub.name): abort(403) if v.shadowbanned: return redirect(f'/h/{sub}/settings') - sub.sidebar = request.values.get('sidebar', '').strip()[:10000] + sub.sidebar = request.values.get('sidebar', '')[:10000].strip() sidebar_html = sanitize(sub.sidebar, blackjack=f"/h/{sub} sidebar") if len(sidebar_html) > 20000: diff --git a/files/routes/users.py b/files/routes/users.py index ba58d4170..4b05cf91d 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -626,7 +626,7 @@ def message2(v, username=None, id=None): if not g.is_tor and get_setting("dm_media"): body = process_files(request.files, v, body, is_dm=True, dm_user=user) - body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT] #process_files potentially adds characters to the post + body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() #process_files potentially adds characters to the post if not body: abort(400, "Message is empty!") @@ -708,7 +708,7 @@ def messagereply(v): if not g.is_tor and get_setting("dm_media"): body = process_files(request.files, v, body, is_dm=True, dm_user=user) - body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT] #process_files potentially adds characters to the post + body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() #process_files potentially adds characters to the post if not body: abort(400, "Message is empty!")