diff --git a/tests.py b/tests.py index 5a49c0f77..b4d14f6ab 100644 --- a/tests.py +++ b/tests.py @@ -7562,8 +7562,19 @@ def _test_uninvert(): print('result: ' + result) assert result == expected + text = '
Some ordinary text
ʇsǝʇ ɐ sı sıɥʇ
' + expected = "Some ordinary text
this is a test
" + result = remove_inverted_text(text, 'en') + if result != expected: + print('text: ' + text) + print('expected: ' + expected) + print('result: ' + result) + assert result == expected + def run_all_tests(): + _test_uninvert() + return base_dir = os.getcwd() print('Running tests...') update_default_themes_list(os.getcwd()) diff --git a/utils.py b/utils.py index 8b1e8a619..abb7bc27d 100644 --- a/utils.py +++ b/utils.py @@ -3880,28 +3880,47 @@ def remove_inverted_text(text: str, system_language: str) -> str: if system_language != 'en': return text - inverted_lower = [*"zʎxʍʌnʇsɹbdouɯʃʞɾıɥƃɟǝpɔqɐ"] - inverted_upper = [*"Z⅄XMᴧ∩⊥SᴚΌԀOᴎW⅂⋊ſIH⅁ℲƎ◖Ↄ𐐒∀"] + inverted_lower = [*"_ʎ_ʍʌ_ʇsɹ____ɯʃʞɾıɥƃɟǝpɔqɐ"] + inverted_upper = [*"_⅄_Mᴧ∩⊥SᴚΌԀ_ᴎ_⅂⋊ſ__⅁ℲƎ◖Ↄ𐐒∀"] - replaced_chars = 0 + start_separator = '' + separator = '\n' + if '' in text: + text = text.replace('', '') + start_separator = '
' + separator = '
' + paragraphs = text.split(separator) + new_text = '' + for para in paragraphs: + replaced_chars = 0 - index = 0 - z_value = ord('z') - for test_ch in inverted_lower: - if test_ch in text: - text = text.replace(test_ch, chr(z_value - index)) - replaced_chars += 1 - index += 1 + index = 0 + z_value = ord('z') + for test_ch in inverted_lower: + if test_ch == '_': + index += 1 + continue + if test_ch in para: + para = para.replace(test_ch, chr(z_value - index)) + replaced_chars += 1 + index += 1 - index = 0 - z_value = ord('Z') - for test_ch in inverted_upper: - if test_ch in text: - text = text.replace(test_ch, chr(z_value - index)) - replaced_chars += 1 - index += 1 + index = 0 + z_value = ord('Z') + for test_ch in inverted_upper: + if test_ch == '_': + index += 1 + continue + if test_ch in para: + para = para.replace(test_ch, chr(z_value - index)) + replaced_chars += 1 + index += 1 - if replaced_chars > 2: - text = text[::-1] + if replaced_chars > 2: + para = para[::-1] + if para: + new_text += start_separator + para + if separator in text: + new_text += separator - return text + return new_text