Bob Mottram 2023-01-19 15:19:22 +00:00
commit 58668f6bd6
3 changed files with 34 additions and 6 deletions

View File

@ -12225,7 +12225,8 @@ class PubServer(BaseHTTPRequestHandler):
calling_domain: str, path: str, calling_domain: str, path: str,
base_dir: str, http_prefix: str, base_dir: str, http_prefix: str,
domain: str, port: int, domain: str, port: int,
debug: str, curr_session) -> bool: debug: str, curr_session,
cookie: str) -> bool:
"""get conversation thread from the date link on a post """get conversation thread from the date link on a post
""" """
if not authorized: if not authorized:
@ -12284,9 +12285,15 @@ class PubServer(BaseHTTPRequestHandler):
if conv_str: if conv_str:
msg = conv_str.encode('utf-8') msg = conv_str.encode('utf-8')
msglen = len(msg) msglen = len(msg)
self._login_headers('text/html', self._login_headers('text/html', msglen, calling_domain)
msglen, calling_domain)
self._write(msg) self._write(msg)
self.server.getreq_busy = False
return True
# redirect to the original site if there are no results
if '://' + self.server.domain_full + '/' in post_id:
self._redirect_headers(post_id, cookie, calling_domain)
else:
self._redirect_headers(post_id, None, calling_domain)
self.server.getreq_busy = False self.server.getreq_busy = False
return True return True
@ -16964,7 +16971,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain, self.server.domain,
self.server.port, self.server.port,
self.server.debug, self.server.debug,
self.server.session): self.server.session,
cookie):
fitness_performance(getreq_start_time, self.server.fitness, fitness_performance(getreq_start_time, self.server.fitness,
'_GET', '_show_conversation_thread', '_GET', '_show_conversation_thread',
self.server.debug) self.server.debug)

View File

@ -54,6 +54,7 @@ from follow import clear_followers
from follow import send_follow_request_via_server from follow import send_follow_request_via_server
from follow import send_unfollow_request_via_server from follow import send_unfollow_request_via_server
from siteactive import site_is_active from siteactive import site_is_active
from utils import html_tag_has_closing
from utils import remove_inverted_text from utils import remove_inverted_text
from utils import remove_square_capitals from utils import remove_square_capitals
from utils import standardize_text from utils import standardize_text
@ -7777,6 +7778,22 @@ def _test_replace_remote_tags() -> None:
assert result == expected assert result == expected
def _test_html_closing_tag() -> None:
print('html_closing_tag')
content = '<p><a href="https://wibbly.wobbly.world/@ooh" ' + \
'class="u-url mention">@ooh@wibbly.wobbly.world</a><span>Like, ' + \
'OMG!<br><br>Something with </span><code>some-widget</code><span> ' + \
'and something else </span>' + \
'<a href="https://www.wibble.com/totally/"><span>totally</span>' + \
'</a><span> on the razzle.<br><br>As for it </span>' + \
'<a href="https://hub.hub/hubbah"><span>WHATEVER</span></a>' + \
'<span> archaeopteryx.</span></p>'
assert html_tag_has_closing('code', content)
content = '<p><code>Some code</p>'
assert not html_tag_has_closing('code', content)
def run_all_tests(): def run_all_tests():
base_dir = os.getcwd() base_dir = os.getcwd()
print('Running tests...') print('Running tests...')
@ -7794,6 +7811,7 @@ def run_all_tests():
_test_checkbox_names() _test_checkbox_names()
_test_thread_functions() _test_thread_functions()
_test_functions() _test_functions()
_test_html_closing_tag()
_test_replace_remote_tags() _test_replace_remote_tags()
_test_replace_variable() _test_replace_variable()
_test_missing_theme_colors(base_dir) _test_missing_theme_colors(base_dir)

View File

@ -1130,7 +1130,7 @@ def _is_dangerous_string_simple(content: str, allow_local_network_access: bool,
return False return False
def _html_tag_has_closing(tag_name: str, content: str) -> bool: def html_tag_has_closing(tag_name: str, content: str) -> bool:
"""Does the given tag have opening and closing labels? """Does the given tag have opening and closing labels?
""" """
content_lower = content.lower() content_lower = content.lower()
@ -1148,9 +1148,11 @@ def _html_tag_has_closing(tag_name: str, content: str) -> bool:
return False return False
if tag_name == 'code': if tag_name == 'code':
# check that lines are not too long # check that lines are not too long
section = section.split(end_tag)[0]
code_lines = section.split('\n') code_lines = section.split('\n')
for line in code_lines: for line in code_lines:
if len(line) >= 60: if len(line) >= 60:
print('<code> line too long')
return False return False
ctr += 1 ctr += 1
return True return True
@ -1166,7 +1168,7 @@ def dangerous_markup(content: str, allow_local_network_access: bool) -> bool:
if _is_dangerous_string_simple(content, allow_local_network_access, if _is_dangerous_string_simple(content, allow_local_network_access,
separators, invalid_strings): separators, invalid_strings):
return True return True
if not _html_tag_has_closing('code', content): if not html_tag_has_closing('code', content):
return True return True
invalid_strings = [ invalid_strings = [
'script', 'noscript', 'pre', 'script', 'noscript', 'pre',