merge-requests/30/head
Bob Mottram 2023-01-07 11:45:19 +00:00
parent 179f4341ee
commit 1bc5f2515e
3 changed files with 25 additions and 32 deletions

View File

@ -14,8 +14,7 @@ from utils import remove_id_ending
from utils import text_in_file from utils import text_in_file
from utils import locate_post from utils import locate_post
from utils import load_json from utils import load_json
from utils import dangerous_markup from utils import harmless_markup
from utils import remove_html
from keys import get_instance_actor_key from keys import get_instance_actor_key
from session import get_json from session import get_json
@ -173,19 +172,8 @@ def download_conversation_posts(session, http_prefix: str, base_dir: str,
if not post_json['object'].get('published'): if not post_json['object'].get('published'):
break break
# remove any dangerous markup # render harmless any dangerous markup
for field_name in ('content', 'summary'): harmless_markup(post_json)
if post_json['object'].get(field_name):
if dangerous_markup(post_json['object'][field_name], False):
post_json['object'][field_name] = \
remove_html(post_json['object'][field_name])
map_name = field_name + 'Map'
if post_json['object'].get(map_name):
map_dict = post_json['object'][map_name].items()
for lang, content in map_dict:
if dangerous_markup(content, False):
content = remove_html(content)
post_json['object'][map_name][lang] = content
conversation_view = [post_json] + conversation_view conversation_view = [post_json] + conversation_view
if not post_json['object'].get('inReplyTo'): if not post_json['object'].get('inReplyTo'):

View File

@ -4257,3 +4257,22 @@ def unescaped_text(txt: str) -> str:
for orig, replacement in _get_escaped_chars().items(): for orig, replacement in _get_escaped_chars().items():
txt = txt.replace(replacement, orig) txt = txt.replace(replacement, orig)
return txt return txt
def harmless_markup(post_json_object: {}) -> None:
"""render harmless any dangerous markup
"""
for field_name in ('content', 'summary'):
if post_json_object['object'].get(field_name):
if dangerous_markup(post_json_object['object'][field_name],
False):
post_json_object['object'][field_name] = \
remove_html(post_json_object['object'][field_name])
map_name = field_name + 'Map'
if post_json_object['object'].get(map_name):
map_dict = post_json_object['object'][map_name].items()
for lang, content in map_dict:
if dangerous_markup(content, False):
content = remove_html(content)
post_json_object['object'][map_name][lang] = \
content

View File

@ -11,8 +11,7 @@ import os
from shutil import copyfile from shutil import copyfile
import urllib.parse import urllib.parse
from datetime import datetime from datetime import datetime
from utils import dangerous_markup from utils import harmless_markup
from utils import remove_html
from utils import remove_id_ending from utils import remove_id_ending
from utils import has_object_dict from utils import has_object_dict
from utils import acct_handle_dir from utils import acct_handle_dir
@ -1194,21 +1193,8 @@ def html_hashtag_search_remote(nickname: str, domain: str, port: int,
print('Hashtag post is not public ' + post_id) print('Hashtag post is not public ' + post_id)
continue continue
# remove any dangerous markup # render harmless any dangerous markup
for field_name in ('content', 'summary'): harmless_markup(post_json_object)
if post_json_object['object'].get(field_name):
if dangerous_markup(post_json_object['object'][field_name],
False):
post_json_object['object'][field_name] = \
remove_html(post_json_object['object'][field_name])
map_name = field_name + 'Map'
if post_json_object['object'].get(map_name):
map_dict = post_json_object['object'][map_name].items()
for lang, content in map_dict:
if dangerous_markup(content, False):
content = remove_html(content)
post_json_object['object'][map_name][lang] = \
content
show_individual_post_icons = False show_individual_post_icons = False
allow_deletion = False allow_deletion = False