Skip to content

Commit e76d1d0

Browse files
committed
Don't compact things as relative IRIs that look like keywords.
Make sure that all keywords that are compacted use `vocab: true`.
1 parent c48d8a7 commit e76d1d0

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

lib/json/ld/api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def self.flatten(input, context, expanded: false, **options)
311311
if context && !flattened.empty?
312312
# Otherwise, return the result of compacting flattened according the Compaction algorithm passing context ensuring that the compaction result uses the @graph keyword (or its alias) at the top-level, even if the context is empty or if there is only one element to put in the @graph array. This ensures that the returned document has a deterministic structure.
313313
compacted = as_array(compact(flattened))
314-
kwgraph = self.context.compact_iri('@graph')
314+
kwgraph = self.context.compact_iri('@graph', vocab: true)
315315
flattened = self.context.
316316
serialize(provided_context: context).
317317
merge(kwgraph => compacted)
@@ -457,7 +457,7 @@ def self.frame(input, frame, expanded: false, **options)
457457
result = if !compacted.is_a?(Array)
458458
compacted
459459
else
460-
kwgraph = context.compact_iri('@graph')
460+
kwgraph = context.compact_iri('@graph', vocab: true)
461461
{kwgraph => compacted}
462462
end
463463
# Only add context if one was provided

lib/json/ld/compact.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def compact(element,
145145
end
146146

147147
unless compacted_value.empty?
148-
al = context.compact_iri('@reverse')
148+
al = context.compact_iri('@reverse', vocab: true)
149149
log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
150150
result[al] = compacted_value
151151
end

lib/json/ld/context.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,8 @@ def compact_iri(iri, base: nil, reverse: false, value: nil, vocab: nil)
14551455
if !vocab
14561456
# transform iri to a relative IRI using the document's base IRI
14571457
iri = remove_base(self.base || base, iri)
1458+
# Make . relative if it has the form of a keyword.
1459+
iri = "./#{iri}" if iri.match?(/^@[a-zA-Z]+$/)
14581460
return iri
14591461
else
14601462
return iri

spec/context_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ def containers
11481148
"nil" => [nil, nil],
11491149
"absolute IRI" => ["http://example.com/", "http://example.com/"],
11501150
"prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1151-
"keyword" => ["@type", "@type"],
11521151
"unmapped" => ["foo", "foo"],
11531152
"bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
11541153
"relative" => ["foo/bar", "http://base/foo/bar"],
@@ -1338,7 +1337,6 @@ def containers
13381337
"nil" => [nil, nil],
13391338
"absolute IRI" => ["http://example.com/", "http://example.com/"],
13401339
"prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
1341-
"keyword" => ["@type", "@type"],
13421340
"unmapped" => ["foo", "foo"],
13431341
"bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
13441342
"relative" => ["foo/bar", "http://base/foo/bar"],

0 commit comments

Comments
 (0)