mirror of https://gitlab.com/bashrc2/epicyon
Render content warnings harmless
parent
1b984f9a30
commit
edbded3143
2
inbox.py
2
inbox.py
|
@ -126,6 +126,7 @@ from utils import dangerous_markup
|
|||
from utils import is_dm
|
||||
from utils import is_reply
|
||||
from utils import has_actor
|
||||
from utils import valid_content_warning
|
||||
from httpsig import message_content_digest
|
||||
from posts import outbox_message_create_wrap
|
||||
from posts import convert_post_content_to_html
|
||||
|
@ -133,7 +134,6 @@ from posts import edited_post_filename
|
|||
from posts import save_post_to_box
|
||||
from posts import is_create_inside_announce
|
||||
from posts import create_direct_message_post
|
||||
from posts import valid_content_warning
|
||||
from posts import download_announce
|
||||
from posts import is_muted_conv
|
||||
from posts import is_image_media
|
||||
|
|
12
posts.py
12
posts.py
|
@ -34,6 +34,7 @@ from webfinger import webfinger_handle
|
|||
from httpsig import create_signed_header
|
||||
from siteactive import site_is_active
|
||||
from languages import understood_post_language
|
||||
from utils import valid_content_warning
|
||||
from utils import get_actor_from_post_id
|
||||
from utils import string_contains
|
||||
from utils import get_post_attachments
|
||||
|
@ -1137,17 +1138,6 @@ def _add_schedule_post(base_dir: str, nickname: str, domain: str,
|
|||
schedule_index_filename + ' ' + str(ex))
|
||||
|
||||
|
||||
def valid_content_warning(summary: str) -> str:
|
||||
"""Returns a validated content warning
|
||||
"""
|
||||
cw_str = remove_html(summary)
|
||||
# hashtags within content warnings apparently cause a lot of trouble
|
||||
# so remove them
|
||||
if '#' in cw_str:
|
||||
cw_str = cw_str.replace('#', '').replace(' ', ' ')
|
||||
return remove_invalid_chars(cw_str)
|
||||
|
||||
|
||||
def _create_post_cw_from_reply(base_dir: str, nickname: str, domain: str,
|
||||
in_reply_to: str,
|
||||
sensitive: bool, summary: str,
|
||||
|
|
2
tests.py
2
tests.py
|
@ -42,7 +42,6 @@ from posts import get_actor_from_in_reply_to
|
|||
from posts import regenerate_index_for_box
|
||||
from posts import remove_post_interactions
|
||||
from posts import get_mentioned_people
|
||||
from posts import valid_content_warning
|
||||
from posts import delete_all_posts
|
||||
from posts import create_public_post
|
||||
from posts import send_post
|
||||
|
@ -56,6 +55,7 @@ from follow import clear_followers
|
|||
from follow import send_follow_request_via_server
|
||||
from follow import send_unfollow_request_via_server
|
||||
from siteactive import site_is_active
|
||||
from utils import valid_content_warning
|
||||
from utils import data_dir
|
||||
from utils import data_dir_testing
|
||||
from utils import remove_link_tracking
|
||||
|
|
17
utils.py
17
utils.py
|
@ -5040,6 +5040,17 @@ def unescaped_text(txt: str) -> str:
|
|||
return txt
|
||||
|
||||
|
||||
def valid_content_warning(summary: str) -> str:
|
||||
"""Returns a validated content warning
|
||||
"""
|
||||
cw_str = remove_html(summary)
|
||||
# hashtags within content warnings apparently cause a lot of trouble
|
||||
# so remove them
|
||||
if '#' in cw_str:
|
||||
cw_str = cw_str.replace('#', '').replace(' ', ' ')
|
||||
return remove_invalid_chars(cw_str)
|
||||
|
||||
|
||||
def harmless_markup(post_json_object: {}) -> None:
|
||||
"""render harmless any dangerous markup
|
||||
"""
|
||||
|
@ -5048,6 +5059,12 @@ def harmless_markup(post_json_object: {}) -> None:
|
|||
|
||||
for field_name in ('content', 'summary'):
|
||||
if post_json_object['object'].get(field_name):
|
||||
# tidy up content warnings
|
||||
if field_name == 'summary':
|
||||
summary = post_json_object['object'][field_name]
|
||||
post_json_object['object'][field_name] = \
|
||||
valid_content_warning(summary)
|
||||
|
||||
if dangerous_markup(post_json_object['object'][field_name],
|
||||
False, ['pre']):
|
||||
post_json_object['object'][field_name] = \
|
||||
|
|
Loading…
Reference in New Issue