Skip to content

toRDF ignores terms with spaces #470

@tpluscode

Description

@tpluscode

I found that jsonld does not parse URIs with spaces. For example, this will return an empty result

import jsonld from "jsonld"

await jsonld.promises.toRDF({
  "@id": "http://example.com/foo bar",
  "@type": "http://example.com/Resource"
})

I worked fine until v2. I tracked it to this place in code. The isAbsolute function is too strict and will reject identifiers which are not fully escaped.

jsonld.js/lib/toRdf.js

Lines 108 to 111 in 20e2286

// skip relative IRI subjects (not valid RDF)
if(!_isAbsoluteIri(id)) {
continue;
}

I find this was explicitly changed in #354 to "Do minimal checking to see if IRIs are valid by making sure they contain no whitespace." Which means that the function no longer only checks whether a URI is absolute or not...

This is problematic because since JavaScript does not have a full-blown URI representation, it is common to come across unescaped URIs, and they have to be taken at face value.

Otherwise, if jsonld wishes to normalise the URIs, the maybe encodeURI would have to be called to ensure 100% correct URIs in the parsed output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions