Skip to content

Commit 3640703

Browse files
committed
Use nil for default value of @protected rather than false, which makes merge logic work better so that protected:true does not override protected:false.
1 parent 8871081 commit 3640703

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/json/ld/context.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def initialize(term,
126126
direction_mapping: nil,
127127
reverse_property: false,
128128
nest: nil,
129-
protected: false,
129+
protected: nil,
130130
simple: false,
131131
prefix: nil,
132132
context: nil)
@@ -336,8 +336,8 @@ def inspect
336336
# @raise [JsonLdError]
337337
# on a remote context load error, syntax error, or a reference to a term which is not defined.
338338
# @return [Context]
339-
def self.parse(local_context, protected: false, override_protected: false, propagate: true, **options)
340-
self.new(**options).parse(local_context, protected: false, override_protected: override_protected, propagate: propagate)
339+
def self.parse(local_context, protected: nil, override_protected: false, propagate: true, **options)
340+
self.new(**options).parse(local_context, protected: protected, override_protected: override_protected, propagate: propagate)
341341
end
342342

343343
##
@@ -550,7 +550,7 @@ def propagate=(value, **options)
550550
# @see https://www.w3.org/TR/json-ld11-api/index.html#context-processing-algorithm
551551
def parse(local_context,
552552
remote_contexts: [],
553-
protected: false,
553+
protected: nil,
554554
override_protected: false,
555555
propagate: true,
556556
validate_scoped: true)
@@ -643,9 +643,8 @@ def parse(local_context,
643643
end.dup()
644644

645645
# if `protected` is true, update term definitions to be protected
646-
# FIXME: if they were explicitly marked not protected, then this will fail
647646
if protected
648-
cached_context.term_definitions.each {|td| td.protected = true}
647+
cached_context.term_definitions.each {|td| td.protected = true if td.protected.nil?}
649648
end
650649

651650
# Merge loaded context noting protected term overriding
@@ -785,7 +784,7 @@ def merge(context, override_protected: false)
785784
# @see https://www.w3.org/TR/json-ld11-api/index.html#create-term-definition
786785
def create_term_definition(local_context, term, defined,
787786
override_protected: false,
788-
protected: false,
787+
protected: nil,
789788
remote_contexts: [],
790789
validate_scoped: true)
791790
# Expand a string value, unless it matches a keyword

0 commit comments

Comments
 (0)