From 45b8b7f237d570098a9af8465811736ea06b7b21 Mon Sep 17 00:00:00 2001 From: Miel Vander Sande Date: Tue, 20 Jan 2026 13:42:50 +0100 Subject: [PATCH] Add check if 'link' in options is instance of dict. --- lib/pyld/jsonld.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index 4151b2c1..2cccff4e 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -498,7 +498,7 @@ def compact(self, input_, ctx, options): options.setdefault('extractAllScripts', False) options.setdefault('processingMode', 'json-ld-1.1') 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 @@ -1589,7 +1589,7 @@ def _compact(self, active_ctx, active_property, element, options): # recursively compact object if _is_object(element): - if(options['link'] and '@id' in element and + if(isinstance(options['link'], dict) and '@id' in element and element['@id'] in options['link']): # check for a linked element to reuse linked = options['link'][element['@id']] @@ -1601,7 +1601,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, options) - 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}) @@ -1637,7 +1637,7 @@ def _compact(self, active_ctx, active_property, element, options): propagate=True, override_protected=True) - 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})