Skip to content

Commit 97c90ce

Browse files
committed
Add tests to make sure that value objects and expanded term definitions have only a single value for @type, unless framing in the case of value objects.
Fixes #484.
1 parent edc3b3d commit 97c90ce

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/json/ld/expand.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,16 @@ def expand(input, active_property, context,
146146
# Otherwise, if the value of result's @value member is not a string and result contains the key @language, an invalid language-tagged value error has been detected (only strings can be language-tagged) and processing is aborted.
147147
raise JsonLdError::InvalidLanguageTaggedValue,
148148
"when @language is used, @value must be a string: #{output_object.inspect}"
149-
elsif framing && !Array(output_object['@type']).all? {|t|
150-
t.is_a?(String) && RDF::URI(t).valid? && !t.start_with?('_:') ||
151-
t.is_a?(Hash) && t.empty?}
149+
elsif output_object['@type'] &&
150+
(!Array(output_object['@type']).all? {|t|
151+
t.is_a?(String) && RDF::URI(t).valid? && !t.start_with?('_:') ||
152+
t.is_a?(Hash) && t.empty?} ||
153+
!framing && !output_object['@type'].is_a?(String))
152154
# Otherwise, if the result has a @type member and its value is not an IRI, an invalid typed value error has been detected and processing is aborted.
153155
raise JsonLdError::InvalidTypedValue,
154156
"value of @type must be an IRI or '@json': #{output_object.inspect}"
155-
elsif !framing && !output_object.fetch('@type', '').is_a?(String)
157+
elsif !framing && !output_object.fetch('@type', '').is_a?(String) &&
158+
RDF::URI(t).valid? && !t.start_with?('_:')
156159
# Otherwise, if the result has a @type member and its value is not an IRI, an invalid typed value error has been detected and processing is aborted.
157160
raise JsonLdError::InvalidTypedValue,
158161
"value of @type must be an IRI or '@json': #{output_object.inspect}"

0 commit comments

Comments
 (0)