diff --git a/utils.py b/utils.py index 4a62fb6db..d97a68193 100644 --- a/utils.py +++ b/utils.py @@ -533,6 +533,16 @@ def get_media_descriptions_from_post(post_json_object: {}) -> str: return descriptions.strip() +def _valid_summary(possible_summary: str) -> bool: + """Returns true if the given summary field is valid + """ + if not isinstance(possible_summary, str): + return False + if len(possible_summary) < 2: + return False + return True + + def get_summary_from_post(post_json_object: {}, system_language: str, languages_understood: []) -> str: """Returns the summary from the post in the given language @@ -543,7 +553,7 @@ def get_summary_from_post(post_json_object: {}, system_language: str, languages_understood, "summary") if summary_str: summary_str = summary_str.strip() - if len(summary_str) < 2: + if not _valid_summary(summary_str): summary_str = '' return summary_str diff --git a/webapp_post.py b/webapp_post.py index da9758764..fd1811c86 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -2716,7 +2716,16 @@ def individual_post_as_html(signing_priv_key_pem: str, if isinstance(post_json_object['object']['sensitive'], bool): # sensitive posts should have a summary if post_json_object['object'].get('summary'): - post_is_sensitive = post_json_object['object']['sensitive'] + possible_summary = \ + get_summary_from_post(post_json_object, + system_language, + languages_understood) + if possible_summary: + post_is_sensitive = \ + post_json_object['object']['sensitive'] + else: + # clear the summary field if it is invalid + post_json_object['object']['summary'] = '' if not post_json_object['object'].get('summary'): post_json_object['object']['summary'] = ''