From c048ca10579efbecc5c14011adf320ad6f83bec3 Mon Sep 17 00:00:00 2001 From: bashrc Date: Sat, 28 Feb 2026 17:12:03 +0000 Subject: [PATCH] Validate before showing LXMF address --- lxmf.py | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/lxmf.py b/lxmf.py index c7b0fb45e..2a0ad9e41 100644 --- a/lxmf.py +++ b/lxmf.py @@ -14,6 +14,18 @@ from utils import remove_html VALID_LXMF_CHARS = set('0123456789abcdefghijklmnopqrstuvwxyz') +def _is_valid_lxmf_address(lxmf_address: str) -> bool: + """Is the given LXMF address valid? + """ + if len(lxmf_address) != 32: + return False + if lxmf_address.lower() != lxmf_address: + return False + if not set(lxmf_address).issubset(VALID_LXMF_CHARS): + return False + return True + + def get_lxmf_address(actor_json: {}) -> str: """Returns lxmf address for the given actor """ @@ -44,35 +56,12 @@ def get_lxmf_address(actor_json: {}) -> str: continue property_value[prop_value_name] = \ property_value[prop_value_name].strip() - if len(property_value[prop_value_name]) != 76: + if not _is_valid_lxmf_address(property_value[prop_value_name]): continue - if property_value[prop_value_name].upper() != \ - property_value[prop_value_name]: - continue - if '"' in property_value[prop_value_name]: - continue - if ' ' in property_value[prop_value_name]: - continue - if ',' in property_value[prop_value_name]: - continue - if '.' in property_value[prop_value_name]: - continue - return remove_html(property_value[prop_value_name]) + return property_value[prop_value_name] return '' -def _is_valid_lxmf_address(lxmf_address: str) -> bool: - """Is the given LXMF address valid? - """ - if len(lxmf_address) != 32: - return False - if lxmf_address.lower() != lxmf_address: - return False - if not set(lxmf_address).issubset(VALID_LXMF_CHARS): - return False - return True - - def set_lxmf_address(actor_json: {}, lxmf_address: str) -> None: """Sets an lxmf address for the given actor """