From 6fb8496901207933e4704597e4c90aad42ac4329 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 17 Feb 2024 19:06:58 +0000 Subject: [PATCH] Limit the maximum length of display names within posts --- webapp_post.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/webapp_post.py b/webapp_post.py index 22b7b5aa8..2d2697307 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -121,6 +121,9 @@ from maps import get_location_from_post from session import get_json_valid from session import get_json +# maximum length for display name within html posts +MAX_DISPLAY_NAME_LENGTH = 42 + def _html_post_metadata_open_graph(domain: str, post_json_object: {}, system_language: str) -> str: @@ -1406,6 +1409,15 @@ def _get_post_title_announce_html(base_dir: str, if len(announce_display_name) < 2 or \ display_name_is_emoji(announce_display_name): announce_display_name = None + if announce_display_name: + # enforce maximum length for display name + if len(announce_display_name) > MAX_DISPLAY_NAME_LENGTH: + if ':' in announce_display_name: + announce_display_name = \ + announce_display_name.split(':')[0].strip() + if len(announce_display_name) > MAX_DISPLAY_NAME_LENGTH: + announce_display_name = \ + announce_display_name[:MAX_DISPLAY_NAME_LENGTH] if not announce_display_name and announce_domain: announce_display_name = announce_nickname + '@' + announce_domain @@ -2410,6 +2422,13 @@ def individual_post_as_html(signing_priv_key_pem: str, display_name_is_emoji(display_name): display_name = None if display_name: + # enforce maximum length for the display name + if len(display_name) > MAX_DISPLAY_NAME_LENGTH: + if ':' in display_name: + display_name = display_name.split(':')[0].strip() + if len(display_name) > MAX_DISPLAY_NAME_LENGTH: + display_name = display_name[:MAX_DISPLAY_NAME_LENGTH] + # add emojis if ':' in display_name: display_name = \ add_emoji_to_display_name(session, base_dir, http_prefix,