Don't replace emoji within json content

main2
Bob Mottram 2019-10-29 13:04:38 +00:00
parent ded29f2527
commit 14d7e2e2b2
3 changed files with 9 additions and 6 deletions

View File

@ -254,7 +254,7 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
def addHtmlTags(baseDir: str,httpPrefix: str, \
nickname: str,domain: str,content: str, \
recipients: [],hashtags: {}) -> str:
recipients: [],hashtags: {},isJsonContent=False) -> str:
""" Replaces plaintext mentions such as @nick@domain into html
by matching against known following accounts
"""
@ -340,9 +340,10 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
content=content.replace(wordStr,replaceStr)
for wordStr,replaceStr in replaceHashTags.items():
content=content.replace(wordStr,replaceStr)
for wordStr,replaceStr in replaceEmoji.items():
content=content.replace(wordStr,replaceStr)
if not isJsonContent:
for wordStr,replaceStr in replaceEmoji.items():
content=content.replace(wordStr,replaceStr)
content=addWebLinks(content)
if longWordsList:
content=removeLongWords(content,maxWordLength,longWordsList)

View File

@ -483,7 +483,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
addHtmlTags(baseDir,httpPrefix, \
nickname,domain,content, \
mentionedRecipients, \
hashtagsDict)
hashtagsDict,True)
statusNumber,published = getStatusNumber()
postTo='https://www.w3.org/ns/activitystreams#Public'

View File

@ -1559,13 +1559,15 @@ def testAddEmoji():
contentModified= \
addHtmlTags(baseDir,httpPrefix, \
nickname,domain,content, \
recipients,hashtags)
recipients,hashtags,True)
assert ':lemon:' in contentModified
tags=[]
for tagName,tag in hashtags.items():
tags.append(tag)
content=contentModified
contentModified=replaceEmojiFromTags(content,tags,'content')
assert 'img src' in contentModified
assert ':lemon:' not in contentModified
os.chdir(baseDirOriginal)
shutil.rmtree(baseDirOriginal+'/.tests')