@@ -584,6 +584,9 @@ def parse(local_context,
584584 context_canon = context . canonicalize
585585 context_canon . scheme == 'http' if context_canon . scheme == 'https'
586586
587+ # If validating a scoped context which has already been loaded, skip to the next one
588+ next if !validate_scoped && remote_contexts . include? ( context . to_s )
589+
587590 remote_contexts << context . to_s
588591 raise JsonLdError ::ContextOverflow , "#{ context } " if remote_contexts . length >= MAX_CONTEXTS_LOADED
589592
@@ -624,11 +627,13 @@ def parse(local_context,
624627 raise JsonLdError ::LoadingRemoteContextFailed , "#{ context_no_base . context_base } : #{ e . message } " , e . backtrace
625628 end
626629
627- # If not validating scoped contexts, simply return the current context to avoid recusion loops.
628- next unless validate_scoped
629-
630630 # 3.2.6) Set context to the result of recursively calling this algorithm, passing context no base for active context, context for local context, and remote contexts.
631- context = context_no_base . parse ( context , remote_contexts : remote_contexts . dup , protected : protected , override_protected : override_protected , propagate : propagate )
631+ context = context_no_base . parse ( context ,
632+ remote_contexts : remote_contexts . dup ,
633+ protected : protected ,
634+ override_protected : override_protected ,
635+ propagate : propagate ,
636+ validate_scoped : validate_scoped )
632637 PRELOADED [ context_canon . to_s ] = context . dup
633638 context . provided_context = result . provided_context
634639 end
@@ -690,6 +695,7 @@ def parse(local_context,
690695 result . create_term_definition ( context , key , defined ,
691696 override_protected : override_protected ,
692697 protected : context . fetch ( '@protected' , protected ) ,
698+ remote_contexts : remote_contexts . dup ,
693699 validate_scoped : validate_scoped
694700 ) unless NON_TERMDEF_KEYS . include? ( key )
695701 end
@@ -753,6 +759,7 @@ def merge!(context)
753759 # @param [Boolean] override_protected Protected terms may be cleared.
754760 # @param [Boolean] propagate
755761 # Context is propagated across node objects.
762+ # @param [Array<String>] remote_contexts
756763 # @param [Boolean] validate_scoped (true).
757764 # Validate scoped context, loading if necessary.
758765 # If false, do not load scoped contexts.
@@ -762,6 +769,7 @@ def merge!(context)
762769 def create_term_definition ( local_context , term , defined ,
763770 override_protected : false ,
764771 protected : false ,
772+ remote_contexts : [ ] ,
765773 validate_scoped : true )
766774 # Expand a string value, unless it matches a keyword
767775 #log_debug("create_term_definition") {"term = #{term.inspect}"}
@@ -977,7 +985,7 @@ def create_term_definition(local_context, term, defined,
977985
978986 if value . has_key? ( '@context' )
979987 begin
980- self . parse ( value [ '@context' ] , override_protected : true , validate_scoped : false )
988+ self . parse ( value [ '@context' ] , override_protected : true , remote_contexts : remote_contexts , validate_scoped : false )
981989 # Record null context in array form
982990 definition . context = value [ '@context' ] ? value [ '@context' ] : [ nil ]
983991 rescue JsonLdError => e
0 commit comments