Validate content warnings

merge-requests/8/head
Bob Mottram 2020-08-25 20:35:55 +01:00
parent 2881e06287
commit 8d6b8f98b0
2 changed files with 28 additions and 1 deletions

View File

@ -47,6 +47,7 @@ from capabilities import getOcapFilename
from capabilities import capabilitiesUpdate
from media import attachMedia
from media import replaceYouTube
from content import removeHtml
from content import removeLongWords
from content import addHtmlTags
from content import replaceEmojiFromTags
@ -654,6 +655,17 @@ def appendEventFields(newPost: {},
newPost['sensitive'] = False
def validContentWarning(cw: str) -> str:
"""Returns a validated content warning
"""
cw = removeHtml(cw)
# hashtags within content warnings apparently cause a lot of trouble
# so remove them
if '#' in cw:
cw = cw.replace('#', '').replace(' ', ' ')
return cw
def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
toUrl: str, ccUrl: str, httpPrefix: str, content: str,
followersOnly: bool, saveToFile: bool, clientToServer: bool,
@ -713,7 +725,7 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
sensitive = False
summary = None
if subject:
summary = subject
summary = validContentWarning(subject)
sensitive = True
toRecipients = []

View File

@ -20,6 +20,7 @@ from cache import getPersonFromCache
from threads import threadWithTrace
from daemon import runDaemon
from session import createSession
from posts import validContentWarning
from posts import deleteAllPosts
from posts import createPublicPost
from posts import sendPost
@ -2041,8 +2042,22 @@ def testRemoveIdEnding():
'https://event.somedomain.net/users/foo/statuses/34544814814'
def testValidContentWarning():
print('testValidContentWarning')
resultStr = validContentWarning('Valid content warning')
assert resultStr == 'Valid content warning'
resultStr = validContentWarning('Invalid #content warning')
assert resultStr == 'Invalid content warning'
resultStr = \
validContentWarning('Invalid <a href="somesite">content warning</a>')
assert resultStr == 'Invalid content warning'
def runAllTests():
print('Running tests...')
testValidContentWarning()
testRemoveIdEnding()
testJsonPostAllowsComments()
runHtmlReplaceQuoteMarks()