mirror of https://gitlab.com/bashrc2/epicyon
Improve validation of summary field
parent
3c540aea3d
commit
85d92d0c22
12
utils.py
12
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
|
||||
|
||||
|
|
|
@ -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'] = ''
|
||||
|
|
Loading…
Reference in New Issue