Skip to content

Commit ec85c4a

Browse files
committed
Don't expand native types as IRIs.
Relates to json-ld/json-ld.org#470.
1 parent 86d32d3 commit ec85c4a

File tree

2 files changed

+301
-196
lines changed

2 files changed

+301
-196
lines changed

lib/json/ld/context.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,14 +1233,16 @@ def compact_iri(iri, value: nil, vocab: nil, reverse: false, quiet: false, **opt
12331233
def expand_value(property, value, useNativeTypes: false, **options)
12341234
#log_debug("expand_value") {"property: #{property.inspect}, value: #{value.inspect}"}
12351235

1236+
td = term_definitions.fetch(property, TermDefinition.new(property))
1237+
12361238
# If the active property has a type mapping in active context that is @id, return a new JSON object containing a single key-value pair where the key is @id and the value is the result of using the IRI Expansion algorithm, passing active context, value, and true for document relative.
1237-
if (td = term_definitions.fetch(property, TermDefinition.new(property))) && td.type_mapping == '@id'
1239+
if value.is_a?(String) && td.type_mapping == '@id'
12381240
#log_debug("") {"as relative IRI: #{value.inspect}"}
12391241
return {'@id' => expand_iri(value, documentRelative: true).to_s}
12401242
end
12411243

12421244
# If active property has a type mapping in active context that is @vocab, return a new JSON object containing a single key-value pair where the key is @id and the value is the result of using the IRI Expansion algorithm, passing active context, value, true for vocab, and true for document relative.
1243-
if td.type_mapping == '@vocab'
1245+
if value.is_a?(String) && td.type_mapping == '@vocab'
12441246
#log_debug("") {"as vocab IRI: #{value.inspect}"}
12451247
return {'@id' => expand_iri(value, vocab: true, documentRelative: true).to_s}
12461248
end
@@ -1276,15 +1278,14 @@ def expand_value(property, value, useNativeTypes: false, **options)
12761278
# Otherwise, initialize result to a JSON object with an @value member whose value is set to value.
12771279
res = {'@value' => value}
12781280

1279-
if td.type_mapping
1281+
if td.type_mapping && !%w(@id @vocab).include?(td.type_mapping.to_s)
12801282
res['@type'] = td.type_mapping.to_s
1281-
elsif value.is_a?(String)
1282-
if td.language_mapping
1283-
res['@language'] = td.language_mapping
1284-
elsif default_language && td.language_mapping.nil?
1285-
res['@language'] = default_language
1286-
end
1283+
elsif value.is_a?(String) && td.language_mapping
1284+
res['@language'] = td.language_mapping
1285+
elsif value.is_a?(String) && default_language && td.language_mapping.nil?
1286+
res['@language'] = default_language
12871287
end
1288+
12881289
res
12891290
end
12901291

0 commit comments

Comments
 (0)