ericprud / SWObjects

Semantic Web swiss army knife C++ libraries
MIT License
15 stars 4 forks source link

Fix problems with base IRIs and IRIs without slashes #3

Closed RubenVerborgh closed 9 years ago

RubenVerborgh commented 9 years ago

This pull requests consists of fixes for two related problems.

A hyphen is used as base IRI when using STDIN

Given the same file no-trailing-slash.rdf:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="a"><a xmlns="a:a#" rdf:resource="https://example.org"/></rdf:Description>
</rdf:RDF>

We get the following result:

$ cat no-trailing-slash.rdf | sparql -l rdfxml -d -
<?xml version='1.0'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<rdf:Description rdf:about='a'><a xmlns='a:a#' rdf:resource='https://example.org-'/></rdf:Description>
</rdf:RDF>

Note the incorrect hyphen at the end of the IRI. This is fixed by 06a70d5.

A URI without trailing slash is not considered absolute

Given the file no-trailing-slash.rdf:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="a"><a xmlns="a:a#" rdf:resource="https://example.org"/></rdf:Description>
</rdf:RDF>

We get the following result:

$ sparql -b https://example.org/foo/bar -l rdfxml -d no-trailing-slash.rdf
<?xml version='1.0'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<rdf:Description rdf:about='https://example.org/foo/a'><a xmlns='a:a#' rdf:resource='https://example.org/foo/bar'/></rdf:Description>
</rdf:RDF

Note how the IRI has suddenly changed to the base IRI. This is fixed by f193c9d.

Remarks

While f193c9d has the intended effect, I am not sure whether it is correct in the context of the relative/absolute IRI algorithm. The intentions of the code were rather hard to grasp for me, so I suggest to inspect closely.

Also, the second fix hides the first one with the above example; though other examples can be found.

ericprud commented 9 years ago

done -- tx!