Skip to content

Commit 4418340

Browse files
committed
Simplify processing mode conflicts to allow mixing different types of contexts.
1 parent 67f310e commit 4418340

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

lib/json/ld/context.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ def default_language=(value)
336336
end
337337

338338
# If contex has a @version member, it's value MUST be 1.1, otherwise an "invalid @version value" has been detected, and processing is aborted.
339-
# If processingMode has been set, and "json-ld-1.1" is not a prefix of processingMode , a "processing mode conflict" has been detecting, and processing is aborted.
339+
# If processingMode has been set, and it is not "json-ld-1.1", a "processing mode conflict" has been detecting, and processing is aborted.
340340
# @param [Number] vaule must be a decimal number
341341
def version=(value)
342342
case value
343343
when 1.1
344-
if processingMode && !processingMode.start_with?("json-ld-1.1")
344+
if processingMode && processingMode < "json-ld-1.1"
345345
raise JsonLdError::ProcessingModeConflict, "#{value} not compatible with #{processingMode}"
346346
end
347-
@processingMode ||= "json-ld-1.1"
347+
@processingMode = "json-ld-1.1"
348348
else
349349
raise JsonLdError::InvalidVersionValue, value
350350
end
@@ -448,9 +448,6 @@ def parse(local_context, remote_contexts = [])
448448
end
449449
raise JsonLdError::InvalidRemoteContext, "#{context}" unless jo.is_a?(Hash) && jo.has_key?('@context')
450450
context = jo['@context']
451-
if (processingMode || 'json-ld-1.0') <= "json-ld-1.1"
452-
context_no_base.provided_context = context.dup
453-
end
454451
end
455452
rescue JsonLdError::LoadingDocumentFailed => e
456453
#log_debug("parse") {"Failed to retrieve @context from remote document at #{context_no_base.context_base.inspect}: #{e.message}"}
@@ -487,11 +484,9 @@ def parse(local_context, remote_contexts = [])
487484
end
488485
end
489486

490-
# If not set explicitly, set processingMode to "json-ld-1.0"
491-
result.processingMode ||= "json-ld-1.0"
492-
493487
defined = {}
494-
# For each key-value pair in context invoke the Create Term Definition subalgorithm, passing result for active context, context for local context, key, and defined
488+
489+
# For each key-value pair in context invoke the Create Term Definition subalgorithm, passing result for active context, context for local context, key, and defined
495490
context.each_key do |key|
496491
result.create_term_definition(context, key, defined)
497492
end
@@ -652,10 +647,10 @@ def create_term_definition(local_context, term, defined)
652647
raise JsonLdError::InvalidKeywordAlias, "expected value of @id to not be @context on term #{term.inspect}" if
653648
definition.id == '@context'
654649

655-
# If id ends with a gen-delim, it may be used as a prefix
650+
# If id ends with a gen-delim, it may be used as a prefix for simple terms
656651
definition.prefix = true if !term.include?(':') &&
657652
definition.id.to_s.end_with?(*%w(: / ? # [ ] @)) &&
658-
(simple_term || ((processingMode || 'json-ld-1.0') == 'json-ld-1.0'))
653+
simple_term
659654
elsif term.include?(':')
660655
# If term is a compact IRI with a prefix that is a key in local context then a dependency has been found. Use this algorithm recursively passing active context, local context, the prefix as term, and defined.
661656
prefix, suffix = term.split(':', 2)

spec/context_spec.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,6 @@ def containers
379379
end
380380

381381
describe "#processingMode" do
382-
it "sets to json-ld-1.0 if not specified" do
383-
[
384-
%({}),
385-
%([{}]),
386-
].each do |str|
387-
ctx = JSON::LD::Context.parse(::JSON.parse(str))
388-
expect(ctx.processingMode).to eql "json-ld-1.0"
389-
end
390-
end
391-
392382
it "sets to json-ld-1.1 if @version: 1.1" do
393383
[
394384
%({"@version": 1.1}),
@@ -414,8 +404,8 @@ def containers
414404
expect {JSON::LD::Context.parse({"@version" => 1.1}, processingMode: "json-ld-1.0")}.to raise_error(JSON::LD::JsonLdError::ProcessingModeConflict)
415405
end
416406

417-
it "raises ProcessingModeConflict nested context is different from starting context" do
418-
expect {JSON::LD::Context.parse([{}, {"@version" => 1.1}])}.to raise_error(JSON::LD::JsonLdError::ProcessingModeConflict)
407+
it "does not raise ProcessingModeConflict nested context is different from starting context" do
408+
expect {JSON::LD::Context.parse([{}, {"@version" => 1.1}])}.not_to raise_error
419409
end
420410
end
421411

0 commit comments

Comments
 (0)