mirror of
https://gitlab.com/bashrc2/epicyon
synced 2026-11-04 19:52:33 +00:00
Validate content warnings
This commit is contained in:
1 parent
2881e06287
commit
8d6b8f98b0
2 files changed
+28
-1
No files matched your search
@@ -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 = []
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user