From ffa23deaab855b4b3ffbf1d5cf4c5d5460968b28 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 8 Apr 2022 17:16:16 +0100 Subject: [PATCH] Fix for empty paragraphs during long string check --- content.py | 2 ++ tests.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/content.py b/content.py index 34dd1bd48..5bd414974 100644 --- a/content.py +++ b/content.py @@ -745,6 +745,7 @@ def remove_long_words(content: str, max_word_length: int, else: content = content[:max_word_length] return content + content = content.replace('

', '

') words = content.split(' ') if not long_words_list: long_words_list = [] @@ -806,6 +807,7 @@ def remove_long_words(content: str, max_word_length: int, if content.startswith('

'): if not content.endswith('

'): content = content.strip() + '

' + content = content.replace('

', '

') return content diff --git a/tests.py b/tests.py index fd0fed64c..ec64f752e 100644 --- a/tests.py +++ b/tests.py @@ -2845,6 +2845,43 @@ def _test_create_person_account(base_dir: str): assert test_post_json['object']['content'] assert '(yawn)' in test_post_json['object']['content'] + content = \ + 'I would regard fediverse as being things based on ActivityPub ' + \ + 'or OStatus. i.e. things whose protocol lineage can be traced ' + \ + 'back to identica/statusnet/pumpio.\n' + \ + '\nFediverse is a vague term though ' + \ + 'and I know some people regard Matrix and Diaspora as being ' + \ + 'fediverse. If fediverse just means any federated system ' + \ + 'then email would be somequitelongword.\nAnotherlongwordhere sentence.' + test_post_json = \ + create_public_post(base_dir, nickname, domain, port, http_prefix, + content, followers_only, save_to_file, + client_to_server, + comments_enabled, attach_image_filename, media_type, + 'Not suitable for Vogons', 'London, England', + test_in_reply_to, test_in_reply_to_atom_uri, + test_subject, test_schedule_post, + test_event_date, test_event_time, test_location, + test_is_article, system_language, conversation_id, + low_bandwidth, content_license_url, + languages_understood) + assert test_post_json + assert test_post_json.get('object') + assert test_post_json['object']['content'] + assert 'Fediverse' in test_post_json['object']['content'] + content_str = test_post_json['object']['content'] + object_content = remove_long_words(content_str, 40, []) + assert 'Fediverse' in object_content + bold_reading = False + object_content = remove_text_formatting(object_content, bold_reading) + assert 'Fediverse' in object_content + object_content = limit_repeated_words(object_content, 6) + assert 'Fediverse' in object_content + object_content = html_replace_email_quote(object_content) + assert 'Fediverse' in object_content + object_content = html_replace_quote_marks(object_content) + assert 'Fediverse' in object_content + os.chdir(curr_dir) shutil.rmtree(base_dir, ignore_errors=False, onerror=None)