Allow jsonld array contains null value
This commit is contained in:
parent
b78ee07af3
commit
a2d4a9295d
2 changed files with 22 additions and 1 deletions
|
@ -111,7 +111,7 @@ module JsonLdHelper
|
||||||
patch_for_forwarding!(value, compacted_value)
|
patch_for_forwarding!(value, compacted_value)
|
||||||
elsif value.is_a?(Array)
|
elsif value.is_a?(Array)
|
||||||
compacted_value = [compacted_value] unless compacted_value.is_a?(Array)
|
compacted_value = [compacted_value] unless compacted_value.is_a?(Array)
|
||||||
return if value.size != compacted_value.size
|
next if value.size != compacted_value.size
|
||||||
|
|
||||||
compacted[key] = value.zip(compacted_value).map do |v, vc|
|
compacted[key] = value.zip(compacted_value).map do |v, vc|
|
||||||
if v.is_a?(Hash) && vc.is_a?(Hash)
|
if v.is_a?(Hash) && vc.is_a?(Hash)
|
||||||
|
|
|
@ -100,6 +100,9 @@ describe JsonLdHelper do
|
||||||
'obsolete' => 'http://ostatus.org#',
|
'obsolete' => 'http://ostatus.org#',
|
||||||
'convo' => 'obsolete:conversation',
|
'convo' => 'obsolete:conversation',
|
||||||
'new' => 'https://obscure-unreleased-test.joinmastodon.org/#',
|
'new' => 'https://obscure-unreleased-test.joinmastodon.org/#',
|
||||||
|
'fedibird' => 'http://fedibird.com/ns#',
|
||||||
|
'searchableBy' => { '@id' => 'fedibird:searchableBy', '@type' => '@id' },
|
||||||
|
'references' => { '@id' => 'fedibird:references', '@type' => '@id' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'type' => 'Create',
|
'type' => 'Create',
|
||||||
|
@ -115,6 +118,16 @@ describe JsonLdHelper do
|
||||||
'href' => ['foo'],
|
'href' => ['foo'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
'searchableBy' => [nil],
|
||||||
|
'references' => {
|
||||||
|
'id' => 'https://streaming.kmy.blue/users/askyq/statuses/111091802894103697/references',
|
||||||
|
'type' => 'Collection',
|
||||||
|
'first' => {
|
||||||
|
'type' => 'CollectionPage',
|
||||||
|
'partOf' => 'https://streaming.kmy.blue/users/askyq/statuses/111091802894103697/references',
|
||||||
|
'items' => ['https://kmy.blue/users/askyq/statuses/111086477431146139'],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'signature' => {
|
'signature' => {
|
||||||
'type' => 'RsaSignature2017',
|
'type' => 'RsaSignature2017',
|
||||||
|
@ -152,6 +165,14 @@ describe JsonLdHelper do
|
||||||
expect(compacted.dig('object', 'tag', 0, 'href')).to eq ['foo']
|
expect(compacted.dig('object', 'tag', 0, 'href')).to eq ['foo']
|
||||||
expect(safe_for_forwarding?(json, compacted)).to be true
|
expect(safe_for_forwarding?(json, compacted)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'is work with invalid array' do
|
||||||
|
json['object'].delete('convo')
|
||||||
|
compacted = compact(json)
|
||||||
|
patch_for_forwarding!(json, compacted)
|
||||||
|
expect(compacted.dig('object', 'searchableBy')).to eq []
|
||||||
|
expect(compacted.dig('object', 'references', 'first', 'items')).to eq ['https://kmy.blue/users/askyq/statuses/111086477431146139']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'safe_for_forwarding?' do
|
describe 'safe_for_forwarding?' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue