summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2016-04-08 18:58:08 +0100
committerMatthew Hodgson <matthew@matrix.org>2016-04-08 18:58:08 +0100
commit1ccabe2965c09a7451fde15cfd082da2a981b882 (patch)
tree1677b4a86851c6dd1fece34475b5808b63eea60a /synapse
parentfix SQL based on PR feedback (diff)
downloadsynapse-1ccabe2965c09a7451fde15cfd082da2a981b882.tar.xz
more PR feedback
Diffstat (limited to 'synapse')
-rw-r--r--synapse/rest/media/v1/preview_url_resource.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/synapse/rest/media/v1/preview_url_resource.py b/synapse/rest/media/v1/preview_url_resource.py
index faa88deb6e..2c86a74c7c 100644
--- a/synapse/rest/media/v1/preview_url_resource.py
+++ b/synapse/rest/media/v1/preview_url_resource.py
@@ -124,12 +124,10 @@ class PreviewUrlResource(BaseMediaResource):
 
             # first check the memory cache - good to handle all the clients on this
             # HS thundering away to preview the same URL at the same time.
-            try:
-                og = self.cache[url]
+            og = self.cache.get(url)
+            if og:
                 respond_with_json_bytes(request, 200, json.dumps(og), send_cors=True)
                 return
-            except:
-                pass
 
             # then check the URL cache in the DB (which will also provide us with
             # historical previews, if we have any)
@@ -197,6 +195,12 @@ class PreviewUrlResource(BaseMediaResource):
                     og = yield self._calc_og(tree, media_info, requester)
                 except UnicodeDecodeError:
                     # XXX: evil evil bodge
+                    # Empirically, sites like google.com mix Latin-1 and utf-8
+                    # encodings in the same page.  The rogue Latin-1 characters
+                    # cause lxml to choke with a UnicodeDecodeError, so if we
+                    # see this we go and do a manual decode of the HTML before
+                    # handing it to lxml as utf-8 encoding, counter-intuitively,
+                    # which seems to make it happier...
                     file = open(media_info['filename'])
                     body = file.read()
                     file.close()