From b602a66dd6471ca4f8f0b2a8931c0059e23ea9d3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 29 Jun 2022 03:13:11 +0200 Subject: [PATCH] fix issue with text exceeding character count despite not exceeding it --- files/routes/comments.py | 8 ++++++-- files/routes/posts.py | 7 +++---- files/routes/users.py | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index f2cfe3324..51a9259a9 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -163,7 +163,9 @@ def api_comment(v): if parent.author_id == v.id: rts = True else: abort(400) - body = request.values.get("body", "").strip()[:10000] + body = request.values.get("body", "").strip().replace('‎','') + + body = body.replace('\r\n', '\n')[:10000] if parent_post.id not in ADMIGGERS: if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): @@ -644,7 +646,9 @@ def edit_comment(cid, v): if c.author_id != v.id: abort(403) - body = request.values.get("body", "").strip()[:10000] + body = request.values.get("body", "").strip().replace('‎','') + + body = body.replace('\r\n', '\n')[:10000] if len(body) < 1 and not (request.files.get("file") and request.headers.get("cf-ipcountry") != "T1"): return {"error":"You have to actually type something!"}, 400 diff --git a/files/routes/posts.py b/files/routes/posts.py index d3139ae4e..6d5f78fc6 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -399,7 +399,7 @@ def edit_post(pid, v): body = request.values.get("body", "").strip().replace('‎','') - if len(body) > 20000: return {"error":"Character limit is 20000!"}, 403 + body = body.replace('\r\n', '\n')[:20000] if v.id == p.author_id: if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): @@ -717,6 +717,8 @@ def submit_post(v, sub=None): body = request.values.get("body", "").strip().replace('‎','') + body = body.replace('\r\n', '\n')[:20000] + def error(error): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": error}, 403 @@ -890,9 +892,6 @@ def submit_post(v, sub=None): g.db.add(ma) return redirect("/notifications") - if len(str(body)) > 20000: - return error("There's a 20000 character limit for text body.") - if len(url) > 2048: return error("There's a 2048 character limit for URLs.") diff --git a/files/routes/users.py b/files/routes/users.py index 52389e34e..9f7998a2d 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -700,7 +700,9 @@ def message2(v, username): @auth_required def messagereply(v): - body = request.values.get("body", "").strip()[:10000].strip() + body = request.values.get("body", "").strip().replace('‎','') + + body = body.replace('\r\n', '\n')[:10000] if not body and not request.files.get("file"): return {"error": "Message is empty!"}