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

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

Open hsolbrig opened this issue 4 years ago • 9 comments

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

hsolbrig avatar Jan 27 '20 15:01 hsolbrig

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

gkellogg avatar Jan 27 '20 17:01 gkellogg

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

hsolbrig avatar Mar 02 '20 20:03 hsolbrig

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

davidlehn avatar Mar 11 '20 19:03 davidlehn

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

hsolbrig avatar Mar 11 '20 19:03 hsolbrig

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.

davidlehn avatar Mar 11 '20 20:03 davidlehn

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

hsolbrig avatar Mar 11 '20 20:03 hsolbrig

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 avatar Mar 11 '20 20:03 davidlehn

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

davidlehn avatar Mar 13 '20 05:03 davidlehn

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

davidlehn avatar Apr 16 '20 02:04 davidlehn