Skip to content

Commit e3b319a

Browse files
committed
Use context loader when loading contexts.
1 parent b5b019d commit e3b319a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/json/ld/context.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def parse(local_context,
273273
log_debug("parse") {"io: #{context}"}
274274
# Load context document, if it is an open file
275275
begin
276-
ctx = JSON.load(context)
276+
ctx = load_context(context, **@options)
277277
raise JSON::LD::JsonLdError::InvalidRemoteContext, "Context missing @context key" if @options[:validate] && ctx['@context'].nil?
278278
result = result.parse(ctx["@context"] ? ctx["@context"] : {})
279279
rescue JSON::ParserError => e
@@ -911,8 +911,7 @@ def serialize(provided_context: nil, **options)
911911
#log_debug "serlialize: reuse context: #{provided_context.inspect}"
912912
provided_context
913913
when IO, StringIO
914-
provided_context.rewind
915-
JSON.load(provided_context).fetch('@context', {})
914+
load_context(provided_context, **@options).fetch('@context', {})
916915
else
917916
ctx = {}
918917
ctx['@version'] = 1.1 if @processingMode == 'json-ld-1.1'
@@ -1689,6 +1688,16 @@ def alias(value)
16891688
CONTEXT_BASE_FRAG_OR_QUERY = %w(? #).freeze
16901689
CONTEXT_TYPE_ID_VOCAB = %w(@id @vocab).freeze
16911690

1691+
##
1692+
# Reads the `@context` from an IO
1693+
def load_context(io, **options)
1694+
io.rewind
1695+
remote_doc = API.loadRemoteDocument(io, **options)
1696+
remote_doc.document.is_a?(String) ?
1697+
MultiJson.load(remote_doc.document) :
1698+
remote_doc.document
1699+
end
1700+
16921701
def uri(value)
16931702
case value.to_s
16941703
when /^_:(.*)$/

0 commit comments

Comments
 (0)