From c8b39b044931caf79d4b61ac5a9f1310fe647aa8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 9 Jul 2021 21:00:02 +0100 Subject: [PATCH] Check string types --- daemon.py | 8 -------- desktop_client.py | 51 ++++++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/daemon.py b/daemon.py index 4b8f7354f..c6c8ef2f1 100644 --- a/daemon.py +++ b/daemon.py @@ -733,10 +733,6 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('Host', callingDomain) self.send_header('InstanceID', self.server.instanceId) 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() def _httpReturnCode(self, httpCode: int, httpDescription: str, @@ -756,10 +752,6 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('Content-Type', 'text/html; charset=utf-8') msgLenStr = str(len(msg)) 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() if not self._write(msg): print('Error when showing ' + str(httpCode)) diff --git a/desktop_client.py b/desktop_client.py index 6382c4d1b..9cf3d799f 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -692,29 +692,40 @@ def _readLocalBoxPost(session, nickname: str, domain: str, if hasObjectDict(postJsonObject2): if postJsonObject2['object'].get('attributedTo') and \ postJsonObject2['object'].get('content'): - actor = postJsonObject2['object']['attributedTo'] - nameStr += ' ' + translate['announces'] + ' ' + \ - getNicknameFromActor(actor) - sayStr = nameStr - _sayCommand(sayStr, sayStr, screenreader, - systemLanguage, espeak) - print('') - if screenreader: - time.sleep(2) - content = \ - _textOnlyContent(postJsonObject2['object']['content']) - content += _getImageDescription(postJsonObject2) - messageStr, detectedLinks = \ - speakableText(baseDir, content, translate) - sayStr = content - _sayCommand(sayStr, messageStr, screenreader, - systemLanguage, espeak) - return postJsonObject2 + attributedTo = postJsonObject2['object']['attributedTo'] + content = postJsonObject2['object']['content'] + if isinstance(attributedTo, str) and \ + isinstance(content, str): + actor = attributedTo + nameStr += ' ' + translate['announces'] + ' ' + \ + getNicknameFromActor(actor) + sayStr = nameStr + _sayCommand(sayStr, sayStr, screenreader, + systemLanguage, espeak) + print('') + if screenreader: + time.sleep(2) + content = \ + _textOnlyContent(content) + content += _getImageDescription(postJsonObject2) + messageStr, detectedLinks = \ + speakableText(baseDir, content, translate) + sayStr = content + _sayCommand(sayStr, messageStr, screenreader, + systemLanguage, espeak) + return postJsonObject2 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) - content = _textOnlyContent(postJsonObject['object']['content']) + content = _textOnlyContent(content) content += _getImageDescription(postJsonObject) if isPGPEncrypted(content):