Check string types

merge-requests/30/head
Bob Mottram 2021-07-09 21:00:02 +01:00
parent 0118168173
commit c8b39b0449
2 changed files with 31 additions and 28 deletions

View File

@ -733,10 +733,6 @@ class PubServer(BaseHTTPRequestHandler):
self.send_header('Host', callingDomain) self.send_header('Host', callingDomain)
self.send_header('InstanceID', self.server.instanceId) self.send_header('InstanceID', self.server.instanceId)
self.send_header('Content-Length', '0') self.send_header('Content-Length', '0')
# self.send_header('X-Robots-Tag',
# 'noindex, nofollow, noarchive, nosnippet')
# self.send_header('Cache-Control', 'public')
# self.send_header('Referrer-Policy', 'origin')
self.end_headers() self.end_headers()
def _httpReturnCode(self, httpCode: int, httpDescription: str, def _httpReturnCode(self, httpCode: int, httpDescription: str,
@ -756,10 +752,6 @@ class PubServer(BaseHTTPRequestHandler):
self.send_header('Content-Type', 'text/html; charset=utf-8') self.send_header('Content-Type', 'text/html; charset=utf-8')
msgLenStr = str(len(msg)) msgLenStr = str(len(msg))
self.send_header('Content-Length', msgLenStr) self.send_header('Content-Length', msgLenStr)
# self.send_header('X-Robots-Tag',
# 'noindex, nofollow, noarchive, nosnippet')
# self.send_header('Cache-Control', 'public')
# self.send_header('Referrer-Policy', 'origin')
self.end_headers() self.end_headers()
if not self._write(msg): if not self._write(msg):
print('Error when showing ' + str(httpCode)) print('Error when showing ' + str(httpCode))

View File

@ -692,7 +692,11 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
if hasObjectDict(postJsonObject2): if hasObjectDict(postJsonObject2):
if postJsonObject2['object'].get('attributedTo') and \ if postJsonObject2['object'].get('attributedTo') and \
postJsonObject2['object'].get('content'): postJsonObject2['object'].get('content'):
actor = postJsonObject2['object']['attributedTo'] attributedTo = postJsonObject2['object']['attributedTo']
content = postJsonObject2['object']['content']
if isinstance(attributedTo, str) and \
isinstance(content, str):
actor = attributedTo
nameStr += ' ' + translate['announces'] + ' ' + \ nameStr += ' ' + translate['announces'] + ' ' + \
getNicknameFromActor(actor) getNicknameFromActor(actor)
sayStr = nameStr sayStr = nameStr
@ -702,7 +706,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
if screenreader: if screenreader:
time.sleep(2) time.sleep(2)
content = \ content = \
_textOnlyContent(postJsonObject2['object']['content']) _textOnlyContent(content)
content += _getImageDescription(postJsonObject2) content += _getImageDescription(postJsonObject2)
messageStr, detectedLinks = \ messageStr, detectedLinks = \
speakableText(baseDir, content, translate) speakableText(baseDir, content, translate)
@ -712,9 +716,16 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
return postJsonObject2 return postJsonObject2
return {} return {}
actor = postJsonObject['object']['attributedTo'] attributedTo = postJsonObject['object']['attributedTo']
if not attributedTo:
return {}
content = postJsonObject['object']['content']
if not isinstance(attributedTo, str) or \
not isinstance(content, str):
return {}
actor = attributedTo
nameStr = getNicknameFromActor(actor) nameStr = getNicknameFromActor(actor)
content = _textOnlyContent(postJsonObject['object']['content']) content = _textOnlyContent(content)
content += _getImageDescription(postJsonObject) content += _getImageDescription(postJsonObject)
if isPGPEncrypted(content): if isPGPEncrypted(content):