Skip to content

Commit 612a8b9

Browse files
committed
Fix expansion bug where a property is @reverse and the same subject has an explicit @reverse.
1 parent 7ddcbbd commit 612a8b9

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/json/ld/expand.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Expand
1313
KEY_ID = %w(@id).freeze
1414
KEYS_VALUE_LANGUAGE_TYPE_INDEX_DIRECTION = %w(@value @language @type @index @direction @annotation).freeze
1515
KEYS_SET_LIST_INDEX = %w(@set @list @index).freeze
16-
KEYS_INCLUDED_TYPE = %w(@included @type).freeze
16+
KEYS_INCLUDED_TYPE_REVERSE = %w(@included @type @reverse).freeze
1717

1818
##
1919
# Expand an Array or Object given an active context and performing local context expansion.
@@ -266,7 +266,7 @@ def expand_object(input, active_property, context, output_object,
266266

267267
# If result has already an expanded property member (other than @type), an colliding keywords error has been detected and processing is aborted.
268268
raise JsonLdError::CollidingKeywords,
269-
"#{expanded_property} already exists in result" if output_object.has_key?(expanded_property) && !KEYS_INCLUDED_TYPE.include?(expanded_property)
269+
"#{expanded_property} already exists in result" if output_object.has_key?(expanded_property) && !KEYS_INCLUDED_TYPE_REVERSE.include?(expanded_property)
270270

271271
expanded_value = case expanded_property
272272
when '@id'

spec/expand_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,6 +3371,43 @@
33713371
}),
33723372
exception: JSON::LD::JsonLdError::InvalidReversePropertyMap,
33733373
},
3374+
"Explicit and implicit @reverse in same object": {
3375+
input: %({
3376+
"@context": {
3377+
"fooOf": {"@reverse": "ex:foo", "@type": "@id"}
3378+
},
3379+
"@id": "ex:s",
3380+
"fooOf": "ex:o1",
3381+
"@reverse": {
3382+
"ex:bar": {"@id": "ex:o2"}
3383+
}
3384+
}),
3385+
output: %([{
3386+
"@id": "ex:s",
3387+
"@reverse": {
3388+
"ex:bar": [{"@id": "ex:o2"}],
3389+
"ex:foo": [{"@id": "ex:o1"}]
3390+
}
3391+
}])
3392+
},
3393+
"Two properties both with @reverse": {
3394+
input: %({
3395+
"@context": {
3396+
"fooOf": {"@reverse": "ex:foo", "@type": "@id"},
3397+
"barOf": {"@reverse": "ex:bar", "@type": "@id"}
3398+
},
3399+
"@id": "ex:s",
3400+
"fooOf": "ex:o1",
3401+
"barOf": "ex:o2"
3402+
}),
3403+
output: %([{
3404+
"@id": "ex:s",
3405+
"@reverse": {
3406+
"ex:bar": [{"@id": "ex:o2"}],
3407+
"ex:foo": [{"@id": "ex:o1"}]
3408+
}
3409+
}])
3410+
},
33743411
}.each do |title, params|
33753412
it(title) {run_expand params}
33763413
end

0 commit comments

Comments
 (0)