From d1a49846faaa0a3af8854319953faf640cc84dba Mon Sep 17 00:00:00 2001 From: ike-agu Date: Wed, 25 Feb 2026 18:07:12 +0000 Subject: [PATCH] Module-Legacy-Code % Implement 280-character limit for Blooms - Implemented length checks in endpoint with HTTP 400 responses. - Added a safety validation in to protect the database layer. --- backend/data/blooms.py | 5 +++++ backend/endpoints.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/backend/data/blooms.py b/backend/data/blooms.py index 7e280cf..2dd917d 100644 --- a/backend/data/blooms.py +++ b/backend/data/blooms.py @@ -16,6 +16,11 @@ class Bloom: def add_bloom(*, sender: User, content: str) -> Bloom: + #------validation----------- + MAX_CHARACTERS = 280 + if len(content) > MAX_CHARACTERS + raise ValueError(f"Bloom exceeds {MAX_CHARACTERS} characters.") + hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] now = datetime.datetime.now(tz=datetime.UTC) diff --git a/backend/endpoints.py b/backend/endpoints.py index 0e177a0..096a76e 100644 --- a/backend/endpoints.py +++ b/backend/endpoints.py @@ -156,6 +156,15 @@ def send_bloom(): if type_check_error is not None: return type_check_error + content = request.json["content"] + + #----Validation----- + if len(content) > 280: + return make_response(jsonify({ + "success": False, + "message" : "Bloom is too long! Max 280 characters" + }), 400) + user = get_current_user() blooms.add_bloom(sender=user, content=request.json["content"])