Skip to content

Commit bec4860

Browse files
committed
When expanding value that might return an array, make sure to concat rather than append.
1 parent e9a0856 commit bec4860

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/json/ld/expand.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def expand(input, active_property, context, ordered: true)
3232
raise JsonLdError::ListOfLists,
3333
"A list may not contain another list" if
3434
is_list && (v.is_a?(Array) || list?(v))
35-
memo << v unless v.nil?
35+
case v
36+
when nil then nil
37+
when Array then memo.concat(v)
38+
else memo << v
39+
end
3640
end
3741

3842
value

spec/expand_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,29 @@
637637
"http://example.com/foo" => []
638638
}]
639639
},
640+
"Free-floating values in sets" => {
641+
input: %({
642+
"@context": {"property": "http://example.com/property"},
643+
"@graph": [{
644+
"@set": [
645+
"free-floating strings in set objects are removed",
646+
{"@id": "http://example.com/free-floating-node"},
647+
{
648+
"@id": "http://example.com/node",
649+
"property": "nodes with properties are not removed"
650+
}
651+
]
652+
}]
653+
}),
654+
output: %([{
655+
"@id": "http://example.com/node",
656+
"http://example.com/property": [
657+
{
658+
"@value": "nodes with properties are not removed"
659+
}
660+
]
661+
}])
662+
}
640663
}.each do |title, params|
641664
it(title) {run_expand params}
642665
end

0 commit comments

Comments
 (0)