digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Inconsistent handling of @ids? #324

Open ptsefton opened 5 years ago

ptsefton commented 5 years ago

There has been a change to the way this library (v1.6.2) handles "@id"="./" when you flatten a document not sure exactly when this changed but it used to leave "./" as-is (and as of today the json-ld playground still does) but now it changes "./" to "/" and prepends "/" to other URIs - also it turns "" into "./" but see above, "./" gets turned back into "/". Why is it doing this? "./" is a valid URI isn't it?

I ran a little experiment to see what happens to various @ids after flattening.

./ -> / / -> / -> ./ .. -> / some_id -> /some_id ./some.file -> /some.file ./some_other.file -> /someother.file :./someother.file -> :b0

Code to generate the above:

const jsonld = require("jsonld");

async function test() { 
    const data = [{"@id": "./"}, {"@id": "/"}, {"@id": ""}, {"@id": ".."}, {"@id": "some_id"}, {"@id": "./some.file"}, {"@id": "./some_other.file"}, {"@id": "_:./some_other.file"}];

    for (let d of data) {
        d["@context"] = {"name" : "http://schema.org/name"}
        d.name = "n"
        var res = await jsonld.flatten(d, {"@context": d["@context"]});
        console.log(`${d["@id"]} -> ${res["@graph"][0]["@id"]}`);
    }

}
test()
dlongley commented 4 years ago

Closing as stale/potentially addressed as updates have come in with the URL resolution code. If there's still an issue, feel free to re-open.

ptsefton commented 4 years ago

Just retested this with 3.1.1 - it's still happening @dlongley

I can't see how to re-open this.