jsonld.js icon indicating copy to clipboard operation
jsonld.js copied to clipboard

Inconsistent handling of @ids?

Open ptsefton opened this issue 4 years ago • 2 comments

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 -> /some_other.file _:./some_other.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()

ptsefton avatar Aug 15 '19 06:08 ptsefton

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.

dlongley avatar May 26 '20 23:05 dlongley

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

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

ptsefton avatar Oct 06 '20 06:10 ptsefton