From 80d2a10610032360b0fde46cfbc01fb51750cd93 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Tue, 31 Jan 2017 10:11:52 -0800 Subject: [PATCH] microformats2: don't crash on raw string values for quotation-of for snarfed/bridgy#723 thanks for reporting @gregorlove! this doesn't (yet) fix the whole bug, but it at least prevents the `'unicode' ... has no attribute 'get'` crash. --- granary/microformats2.py | 2 +- .../note_with_string_quotation.as-from-mf2.json | 9 +++++++++ .../testdata/note_with_string_quotation.mf2.json | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 granary/test/testdata/note_with_string_quotation.as-from-mf2.json create mode 100644 granary/test/testdata/note_with_string_quotation.mf2.json diff --git a/granary/microformats2.py b/granary/microformats2.py index bb8cd3bf..97a54fec 100644 --- a/granary/microformats2.py +++ b/granary/microformats2.py @@ -283,7 +283,7 @@ def absolute_urls(prop): attachments = [ json_to_object(quote) for quote in mf2.get('children', []) + props.get('quotation-of', []) - if 'h-cite' in set(quote.get('type', []))] + if isinstance(quote, dict) and 'h-cite' in set(quote.get('type', []))] obj = { 'id': prop.get('uid'), diff --git a/granary/test/testdata/note_with_string_quotation.as-from-mf2.json b/granary/test/testdata/note_with_string_quotation.as-from-mf2.json new file mode 100644 index 00000000..c4ff6b13 --- /dev/null +++ b/granary/test/testdata/note_with_string_quotation.as-from-mf2.json @@ -0,0 +1,9 @@ +{ + "objectType": "note", + "content": "i hereby quote", + "attachments": [{ + "objectType": "note", + "content": "this is being quoted", + "url": "http://quoted/post" + }] +} diff --git a/granary/test/testdata/note_with_string_quotation.mf2.json b/granary/test/testdata/note_with_string_quotation.mf2.json new file mode 100644 index 00000000..77f1fba5 --- /dev/null +++ b/granary/test/testdata/note_with_string_quotation.mf2.json @@ -0,0 +1,16 @@ +{ + "type": ["h-entry"], + "properties": { + "content": ["i hereby quote"], + "quotation-of": [ + "this should be ignored", + { + "type": ["h-cite"], + "properties": { + "content": ["this is being quoted"], + "url": ["http://quoted/post"] + } + } + ] + } +}