From 878af522c1ac458809fc3b183973ae3c5fc91ea5 Mon Sep 17 00:00:00 2001 From: Bradford Powell Date: Tue, 19 Sep 2017 16:16:55 -0400 Subject: [PATCH] check isinstance(options['link'], dict) An empty dict is not truthy in python, so cannot just check for "if options['link']" Fixes #64 --- lib/pyld/jsonld.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index 42f98057..7f92aca6 100755 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -712,7 +712,7 @@ def compact(self, input_, ctx, options): options.setdefault('activeCtx', False) options.setdefault('documentLoader', _default_document_loader) options.setdefault('link', False) - if options['link']: + if isinstance(options['link'], dict): # force skip expansion when linking, "link" is not part of the # public API, it should only be called from framing options['skipExpansion'] = True @@ -1752,7 +1752,7 @@ def _compact(self, active_ctx, active_property, element, options): if _is_value(element) or _is_subject_reference(element): rval = self._compact_value( active_ctx, active_property, element) - if options['link'] and _is_subject_reference(element): + if isinstance(options['link'], dict) and _is_subject_reference(element): # store linked element options['link'].setdefault(element['@id'], []).append( {'expanded': element, 'compacted': rval}) @@ -1763,7 +1763,7 @@ def _compact(self, active_ctx, active_property, element, options): rval = {} - if options['link'] and '@id' in element: + if isinstance(options['link'], dict) and '@id' in element: # store linked element options['link'].setdefault(element['@id'], []).append( {'expanded': element, 'compacted': rval})