Extra checks for bad content format

main
Bob Mottram 2020-05-12 10:34:58 +01:00
parent b0bfb96a49
commit 315afa4bd8
2 changed files with 22 additions and 0 deletions

View File

@ -355,11 +355,23 @@ def addMention(wordStr: str, httpPrefix: str, following: str,
return True return True
def replaceContentDuplicates(content: str) -> str:
"""Replaces invalid duplicates within content
"""
while '<<' in content:
content = content.replace('<<', '<')
while '>>' in content:
content = content.replace('>>', '>')
content = content.replace('<\p>', '')
return content
def removeLongWords(content: str, maxWordLength: int, def removeLongWords(content: str, maxWordLength: int,
longWordsList: []) -> str: longWordsList: []) -> str:
"""Breaks up long words so that on mobile screens this doesn't """Breaks up long words so that on mobile screens this doesn't
disrupt the layout disrupt the layout
""" """
content = replaceContentDuplicates(content)
if ' ' not in content: if ' ' not in content:
# handle a single very long string with no spaces # handle a single very long string with no spaces
contentStr = content.replace('<p>', '').replace(r'<\p>', '') contentStr = content.replace('<p>', '').replace(r'<\p>', '')

View File

@ -66,6 +66,7 @@ from content import addWebLinks
from content import replaceEmojiFromTags from content import replaceEmojiFromTags
from content import addHtmlTags from content import addHtmlTags
from content import removeLongWords from content import removeLongWords
from content import replaceContentDuplicates
from theme import setCSSparam from theme import setCSSparam
testServerAliceRunning = False testServerAliceRunning = False
@ -1641,6 +1642,15 @@ def testWebLinks():
assert resultText == exampleText assert resultText == exampleText
assert 'ellipsis' not in resultText assert 'ellipsis' not in resultText
exampleText = \
'<p>' + \
'<<\p>'
resultText = replaceContentDuplicates(exampleText)
print(resultText)
assert resultText == \
'<p>' + \
''
def testAddEmoji(): def testAddEmoji():
print('testAddEmoji') print('testAddEmoji')