Skip to content

Commit 83ed915

Browse files
committed
Make sure list members don't have annotations.
1 parent 940ca01 commit 83ed915

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

lib/json/ld/expand.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ def expand(input, active_property, context,
4949
log_depth: log_depth.to_i + 1)
5050

5151
# If the active property is @list or its container mapping is set to @list and v is an array, change it to a list object
52-
v = {"@list" => v} if is_list && v.is_a?(Array)
52+
if is_list && v.is_a?(Array)
53+
# Make sure that no member of v contains an annotation object
54+
raise JsonLdError::InvalidAnnotation,
55+
"A list element must not contain @annotation." if
56+
v.any? {|n| n.is_a?(Hash) && n.key?('@annotation')}
57+
v = {"@list" => v}
58+
end
5359

5460
case v
5561
when nil then nil
@@ -486,6 +492,11 @@ def expand_object(input, active_property, context, output_object,
486492
# Spec FIXME: need to be sure that result is an array
487493
value = as_array(value)
488494

495+
# Make sure that no member of value contains an annotation object
496+
raise JsonLdError::InvalidAnnotation,
497+
"A list element must not contain @annotation." if
498+
value.any? {|n| n.is_a?(Hash) && n.key?('@annotation')}
499+
489500
value
490501
when '@set'
491502
# If expanded property is @set, set expanded value to the result of using this algorithm recursively, passing active context, active property, and value for element.

script/tc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def run_tc(man, tc, options)
9898
expected = JSON.load(tc.expect) if tc.evaluationTest? && tc.positiveTest?
9999
compare_results(tc, output, expected)
100100
when 'jld:FromRDFTest'
101-
repo = RDF::Repository.load(tc.input_loc, format: :nquads)
101+
repo = RDF::Repository.load(tc.input_loc, format: :nquads, rdfstar: tc.options[:rdfstar])
102102
output = if options[:stream]
103103
JSON.parse(JSON::LD::Writer.buffer(stream: true, validate: true, **tc.options) {|w| w << repo})
104104
else
@@ -129,11 +129,11 @@ def run_tc(man, tc, options)
129129
# toRdf/e075 is hard to test, but verified manually
130130
output == tc.expect ? 'passed' : (tc.input_loc.include?('e075') ? 'passed' : 'failed')
131131
else
132-
expected = RDF::Repository.new << RDF::NQuads::Reader.new(tc.expect, validate: false, logger: [])
132+
expected = RDF::Repository.new << RDF::NQuads::Reader.new(tc.expect, rdfstar: tc.options[:rdfstar], validate: false, logger: [])
133133
output.isomorphic?(expected) ? 'passed' : 'failed'
134134
end
135135
rescue RDF::ReaderError, JSON::LD::JsonLdError
136-
quads = JSON::LD::API.toRdf(tc.input_loc, tc.options.merge(validate: false)).map do |statement|
136+
quads = JSON::LD::API.toRdf(tc.input_loc, rdfstar: tc.options[:rdfstar], **tc.options.merge(validate: false)).map do |statement|
137137
# Not really RDF, try different test method
138138
tc.to_quad(statement)
139139
end
@@ -254,7 +254,10 @@ else
254254
%w(expand compact flatten fromRdf html remote-doc toRdf).map do |man|
255255
"#{Fixtures::SuiteTest::SUITE}#{man}-manifest.jsonld"
256256
end +
257-
["#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld"]
257+
["#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld"] +
258+
%w{expand compact flatten fromRdf toRdf}.map do |man|
259+
"#{Fixtures::SuiteTest::STAR_SUITE}#{man}-manifest.jsonld"
260+
end
258261
end
259262

260263
earl_preamble(options) if options[:earl]

spec/expand_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,7 @@
37983798
"@id": "ex:bob",
37993799
"ex:knows": {
38003800
"@list": [{"@id": "ex:fred"}],
3801-
"@annotation": "value2"
3801+
"@annotation": {"ex:prop": "value2"}
38023802
}
38033803
}),
38043804
exception: JSON::LD::JsonLdError::InvalidSetOrListObject
@@ -3810,7 +3810,7 @@
38103810
"@list": [
38113811
{
38123812
"@id": "ex:fred",
3813-
"@annotation": "value2"
3813+
"@annotation": {"ex:prop": "value2"}
38143814
}
38153815
]
38163816
}

spec/suite_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def run(rspec_example = nil)
203203
logger.info "frame: #{frame}" if frame_loc
204204

205205
options = self.options
206-
unless options[:specVersion] == "json-ld-1.1"
207-
skip "not a 1.1 test"
206+
if options[:specVersion] == "json-ld-1.0"
207+
skip "1.0 test"
208208
return
209209
end
210210

@@ -225,7 +225,7 @@ def run(rspec_example = nil)
225225
JSON::LD::API.frame(input_loc, frame_loc, logger: logger, **options)
226226
when "jld:FromRDFTest"
227227
# Use an array, to preserve input order
228-
repo = RDF::NQuads::Reader.open(input_loc) do |reader|
228+
repo = RDF::NQuads::Reader.open(input_loc, rdfstar: options[:rdfstar]) do |reader|
229229
reader.each_statement.to_a
230230
end.to_a.uniq.extend(RDF::Enumerable)
231231
logger.info "repo: #{repo.dump(self.id == '#t0012' ? :nquads : :trig)}"
@@ -258,7 +258,7 @@ def run(rspec_example = nil)
258258
end
259259
if evaluationTest?
260260
if testType == "jld:ToRDFTest"
261-
expected = RDF::Repository.new << RDF::NQuads::Reader.new(expect, logger: [])
261+
expected = RDF::Repository.new << RDF::NQuads::Reader.new(expect, rdfstar: options[:rdfstar], logger: [])
262262
rspec_example.instance_eval {
263263
expect(result).to be_equivalent_graph(expected, logger)
264264
}
@@ -314,7 +314,7 @@ def run(rspec_example = nil)
314314
when "jld:FrameTest"
315315
JSON::LD::API.frame(t.input_loc, t.frame_loc, logger: logger, **options)
316316
when "jld:FromRDFTest"
317-
repo = RDF::Repository.load(t.input_loc)
317+
repo = RDF::Repository.load(t.input_loc, rdfstar: options[:rdfstar])
318318
logger.info "repo: #{repo.dump(t.id == '#t0012' ? :nquads : :trig)}"
319319
JSON::LD::API.fromRdf(repo, logger: logger, **options)
320320
when "jld:HttpTest"

0 commit comments

Comments
 (0)