digitalbazaar / jsonld.js

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

`@included` behaves incorrectly if `@context` follows entry #358

Open hsolbrig opened 4 years ago

hsolbrig commented 4 years ago

See: http://tinyurl.com/r8chydx

If the @context entry precedes the @included, behavior is as expected. If at the end, @included maps to http://example.org/@included

gkellogg commented 4 years ago

Full support for @included is in https://github.com/digitalbazaar/jsonld.js/pull/349.

hsolbrig commented 4 years ago

The issue seems to have been fixed in the above example, but https://tinyurl.com/ura2qxv still has it.

davidlehn commented 4 years ago

A newer jsonld.js was released and the playground updated. Did that solve this issue?

hsolbrig commented 4 years ago

Unfortunately, I'm getting a hang when I use the above link.

davidlehn commented 4 years ago

Yup. I was hoping no one would notice. ;-) Locking the whole tab up, which is strange. Maybe something recursive in those contexts? Will have to investigate.

hsolbrig commented 4 years ago

Ya - the contexts are recursive as all getout -- I thought that was ok...

davidlehn commented 4 years ago

In Node.js it first flips out on https://fhircat.org/fhir/contexts/r5/medicationadministration.context.jsonld.

No special encoding was specified:

$ curl -I https://fhircat.org/fhir/contexts/r5/medicationadministration.context.jsonld
[...]
Content-Type: application/ld+json
[...]

It has BOM bytes:

$ file medicationadministration.context.jsonld 
medicationadministration.context.jsonld: UTF-8 Unicode (with BOM) text
$ curl -O https://fhircat.org/fhir/contexts/r5/medicationadministration.context.jsonld
$ xxd -l 16 medicationadministration.context.jsonld
00000000: efbb bf7b 0a20 2022 4063 6f6e 7465 7874  ...{.  "@context

JSON.parse isn't liking that in node:

  [...]
  name: 'jsonld.InvalidUrl',
  details: {
    code: 'loading remote context failed',
    url: 'https://fhircat.org/fhir/contexts/r5/medicationadministration.context.jsonld',   
    cause: SyntaxError: Unexpected token  in JSON at position 0
        at JSON.parse (<anonymous>)
        at ContextResolver._fetchContext (.../jsonld.js/lib/ContextResolver.js:159:24)
  [...]

I have no idea what tools should do with that. It's easy enough to fix, if that's the right thing to do. I don't know. I think browser is ok with it. In Node it then proceeds to blow it's heap limits and crash the vm. I assume that's what happens in the browser as well. So somewhere recursion is not handled well.

davidlehn commented 4 years ago

Working on a scoped context recursion fix: https://github.com/digitalbazaar/jsonld.js/pull/381

davidlehn commented 4 years ago

Playground has been updated. Failing to load the files, but I think that's just due to the BOM character issue.