Validate content warnings

main
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 capabilities import capabilitiesUpdate
from media import attachMedia from media import attachMedia
from media import replaceYouTube from media import replaceYouTube
from content import removeHtml
from content import removeLongWords from content import removeLongWords
from content import addHtmlTags from content import addHtmlTags
from content import replaceEmojiFromTags from content import replaceEmojiFromTags
@ -654,6 +655,17 @@ def appendEventFields(newPost: {},
newPost['sensitive'] = False 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, def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
toUrl: str, ccUrl: str, httpPrefix: str, content: str, toUrl: str, ccUrl: str, httpPrefix: str, content: str,
followersOnly: bool, saveToFile: bool, clientToServer: bool, followersOnly: bool, saveToFile: bool, clientToServer: bool,
@ -713,7 +725,7 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
sensitive = False sensitive = False
summary = None summary = None
if subject: if subject:
summary = subject summary = validContentWarning(subject)
sensitive = True sensitive = True
toRecipients = [] toRecipients = []

View File

@ -20,6 +20,7 @@ from cache import getPersonFromCache
from threads import threadWithTrace from threads import threadWithTrace
from daemon import runDaemon from daemon import runDaemon
from session import createSession from session import createSession
from posts import validContentWarning
from posts import deleteAllPosts from posts import deleteAllPosts
from posts import createPublicPost from posts import createPublicPost
from posts import sendPost from posts import sendPost
@ -2041,8 +2042,22 @@ def testRemoveIdEnding():
'https://event.somedomain.net/users/foo/statuses/34544814814' '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(): def runAllTests():
print('Running tests...') print('Running tests...')
testValidContentWarning()
testRemoveIdEnding() testRemoveIdEnding()
testJsonPostAllowsComments() testJsonPostAllowsComments()
runHtmlReplaceQuoteMarks() runHtmlReplaceQuoteMarks()