Skip to content

Commit f73809a

Browse files
committed
Fix invalid handling of rdf:parseType=Collection and rdf:ID
1 parent 98d6ab5 commit f73809a

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/RdfXmlParser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,13 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
379379
const restTerm = this.dataFactory.namedNode(RdfXmlParser.RDF + 'rest');
380380

381381
// Emit <x> <p> <current-chain> OR <previous-chain> <rdf:rest> <current-chain>
382+
const isRestTerm = parentTag.childrenCollectionPredicate.equals(restTerm);
382383
this.emitTriple(parentTag.childrenCollectionSubject,
383-
parentTag.childrenCollectionPredicate, linkTerm, parentTag.reifiedStatementId, parentTag.childrenTripleTerms, parentTag.childrenCollectionPredicate.equals(restTerm) ? null : parentTag.reifier);
384+
parentTag.childrenCollectionPredicate, linkTerm, isRestTerm ? null : parentTag.reifiedStatementId, parentTag.childrenTripleTerms, isRestTerm ? null : parentTag.reifier);
384385

385386
// Emit <current-chain> <rdf:first> value
386387
this.emitTriple(linkTerm, this.dataFactory.namedNode(RdfXmlParser.RDF + 'first'),
387-
activeTag.subject, activeTag.reifiedStatementId, activeTag.childrenTripleTerms);
388+
activeTag.subject, null, activeTag.childrenTripleTerms);
388389

389390
// Store <current-chain> in the parent node
390391
parentTag.childrenCollectionSubject = linkTerm;
@@ -718,7 +719,7 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
718719
if (poppedTag.childrenCollectionSubject) {
719720
// Terminate the rdf:List
720721
this.emitTriple(poppedTag.childrenCollectionSubject, poppedTag.childrenCollectionPredicate,
721-
this.dataFactory.namedNode(RdfXmlParser.RDF + 'nil'), poppedTag.reifiedStatementId, poppedTag.childrenTripleTerms);
722+
this.dataFactory.namedNode(RdfXmlParser.RDF + 'nil'), null, poppedTag.childrenTripleTerms);
722723
} else if (poppedTag.predicate) {
723724
if (!poppedTag.hadChildren && poppedTag.childrenParseType !== ParseType.PROPERTY) {
724725
// Property element contains text

test/RdfXmlParser-test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,38 @@ abc`)).rejects.toBeTruthy();
21752175
]);
21762176
});
21772177

2178+
it('rdf:parseType="Collection" and rdf:ID', async () => {
2179+
const array = await parse(parser, `<?xml version="1.0"?>
2180+
<rdf:RDF
2181+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
2182+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
2183+
xmlns:eg="http://example.org/eg#"
2184+
xml:base="http://example.com/">
2185+
2186+
<rdf:Description rdf:about="http://example.org/eg#eric">
2187+
<rdf:type rdf:parseType="Resource">
2188+
<eg:intersectionOf rdf:ID="reif" rdf:parseType="Collection">
2189+
<rdf:Description rdf:about="http://example.org/eg#Person"/>
2190+
<rdf:Description rdf:about="http://example.org/eg#Male"/>
2191+
</eg:intersectionOf>
2192+
</rdf:type>
2193+
</rdf:Description>
2194+
</rdf:RDF>`);
2195+
return expect(array)
2196+
.toBeRdfIsomorphic([
2197+
quad('http://example.org/eg#eric', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', '_:b99_a0'),
2198+
quad('_:b99_a0', 'http://example.org/eg#intersectionOf', '_:b99_a1'),
2199+
quad('http://example.com/#reif', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#subject', '_:b99_a0'),
2200+
quad('http://example.com/#reif', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate', 'http://example.org/eg#intersectionOf'),
2201+
quad('http://example.com/#reif', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#object', '_:b99_a1'),
2202+
quad('http://example.com/#reif', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement'),
2203+
quad('_:b99_a1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', 'http://example.org/eg#Person'),
2204+
quad('_:b99_a1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', '_:b99_a2'),
2205+
quad('_:b99_a2', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', 'http://example.org/eg#Male'),
2206+
quad('_:b99_a2', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'),
2207+
]);
2208+
});
2209+
21782210
// 2.17
21792211
it('rdf:ID on a property with a literal to a reified statement', async () => {
21802212
const array = await parse(parser, `<?xml version="1.0"?>

0 commit comments

Comments
 (0)