Title: rdf/turtle: JSON-LD @context array form not handled — locally-resolvable contexts only · Issue #389 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub
Open Graph Title: rdf/turtle: JSON-LD @context array form not handled — locally-resolvable contexts only · Issue #389 · JavaScriptSolidServer/JavaScriptSolidServer
X Title: rdf/turtle: JSON-LD @context array form not handled — locally-resolvable contexts only · Issue #389 · JavaScriptSolidServer/JavaScriptSolidServer
Description: Surfaced during #388 (Phase A of #386). Symptom JSON-LD documents with @context in array form (e.g. [ "https://www.w3.org/ns/cid/v1", { ...inline prefixes... } ]) lose all term expansion when converted to Turtle via the conneg layer. Pre...
Open Graph Description: Surfaced during #388 (Phase A of #386). Symptom JSON-LD documents with @context in array form (e.g. [ "https://www.w3.org/ns/cid/v1", { ...inline prefixes... } ]) lose all term expansion when conve...
X Description: Surfaced during #388 (Phase A of #386). Symptom JSON-LD documents with @context in array form (e.g. [ "https://www.w3.org/ns/cid/v1", { ...inline prefixes... } ]) lose all term expansion ...
Opengraph URL: https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/389
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"rdf/turtle: JSON-LD @context array form not handled — locally-resolvable contexts only","articleBody":"Surfaced during #388 (Phase A of #386).\n\n## Symptom\n\nJSON-LD documents with `@context` in array form (e.g. `[ \"https://www.w3.org/ns/cid/v1\", { ...inline prefixes... } ]`) lose all term expansion when converted to Turtle via the conneg layer. Predicates appear as bare relative IRIs (`\u003cinbox>`, `\u003ccontroller>`, etc.) instead of expanding to their full namespace URIs.\n\n## Reproduction (during #388 development)\n\nSwitching `src/webid/profile.js` to emit `@context` as an array with `https://www.w3.org/ns/cid/v1` first caused the existing `#320` Turtle conneg test to fail. Output excerpt:\n\n```turtle\n\u003chttp://...#me> a foaf:Person, schema:Person;\n foaf:name \"webidturtletest\";\n \u003cinbox> \"http://...inbox/\";\n \u003cstorage> \"http://...\";\n \u003coidcIssuer> \"http://...\";\n ...\n \u003cservice> \u003chttp://...#oidc>.\n\u003chttp://...#oidc> a \u003clws:OpenIdProvider>;\n \u003cserviceEndpoint> \"http://...\".\n```\n\nEvery term is a bare relative IRI. Should be `ldp:inbox`, `pim:storage`, `solid:oidcIssuer`, etc.\n\n## Root cause\n\n`src/rdf/turtle.js:182`:\n\n```js\nmergedContext = { ...mergedContext, ...doc['@context'] };\n```\n\nA shallow object spread. When `doc['@context']` is an array, this copies array indices `0`, `1`, … as keys, breaking lookups. The function silently produces a context object where only the inline-object form survives — and only if it's a single object, not an array element.\n\n## Design constraint: don't fetch remote contexts\n\nJSS deliberately doesn't dereference external context URLs at conversion time. Doing so would:\n\n- **SSRF risk**: any URL in any user-supplied JSON-LD becomes a fetch trigger from the server\n- **Reliability**: depend on third-party context hosts at request time\n- **Latency**: every Turtle conneg becomes an outbound HTTPS round-trip\n- **Cache complexity**: external contexts can change; do we cache, validate, refresh?\n\nSo the fix should *not* be \"fetch the URL and merge it.\" Two reasonable fixes that preserve the no-remote-fetch invariant:\n\n### Option A — handle array form, ignore string entries\n\nIterate `@context` if it's an array; merge each entry that is an object, ignore each entry that is a string URL. Documents that need the URL-imported context's terms must declare those terms inline too (the pattern #388 ended up using).\n\n```js\nfunction mergeContext(target, ctx) {\n if (!ctx) return target;\n if (Array.isArray(ctx)) {\n for (const entry of ctx) mergeContext(target, entry);\n return target;\n }\n if (typeof ctx === 'object') return Object.assign(target, ctx);\n // String URLs ignored — JSS doesn't fetch external contexts\n return target;\n}\n```\n\nThis makes JSS tolerate the array form (which is increasingly common — CID v1 docs, VC docs, DID docs all use it) without changing the no-fetch policy.\n\n### Option B — bundle well-known contexts as static files\n\nShip a small in-tree map of `URL → static-context-object` for the contexts JSS itself emits or expects (CID v1, AS2, DID core, schema.org subset). Reads cost zero — the file is just `import` ed at startup.\n\nPros: documents using `@context: [\"https://www.w3.org/ns/cid/v1\", {…}]` get the imported terms expanded correctly without any network. Solves both #388 and any future LWS / VC / DID work.\n\nCons: a small set of contexts that need maintenance when upstream changes. Mitigation: snapshot via test, alert on diff during periodic CI run.\n\n### Combined\n\nProbably the right answer is **A first, B opportunistically.** A makes the array form non-crashing; B adds *real* support for canonical W3C contexts as we need them.\n\n## Acceptance\n\n- [ ] `src/rdf/turtle.js` accepts array `@context` without losing term expansion from inline objects in the same array\n- [ ] String entries in `@context` arrays are ignored gracefully (no fetch attempted)\n- [ ] Test: a JSON-LD document with `@context: [\"https://www.w3.org/ns/cid/v1\", { foaf, … }]` round-trips to Turtle with `foaf:name` etc. preserved\n- [ ] (Optional, separate PR) Bundled-context map for CID v1 + a couple of common LWS/W3C contexts\n\n## Refs\n\n- #388 — Phase A of #386, where this surfaced\n- #386 — LWS profile-to-key linking tracker\n- `src/rdf/turtle.js:170-190` — the merging logic\n- [JSON-LD 1.1: §4.1.2 The Context (array form)](https://www.w3.org/TR/json-ld11/#advanced-context-usage)","author":{"url":"https://github.com/melvincarvalho","@type":"Person","name":"melvincarvalho"},"datePublished":"2026-05-09T04:15:33Z","url":"https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/389"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4c4d46ac-118b-4307-e4c9-a7e08d13cfd9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1B8:5DF53:4CA636:60E5CB:6B038A4E |
| html-safe-nonce | 9f07fe84ccc4e630df612616bbe3536bd07e65a5d7620dffc3160cd874290cfb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUI4OjVERjUzOjRDQTYzNjo2MEU1Q0I6NkIwMzhBNEUiLCJ2aXNpdG9yX2lkIjoiNDc5NDYyOTIyNDQ4Mjk2NjA5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a56d1c5ecbbbc2dddf7f61a8cbe7754b2acc0d0e50bcf51dea02f4bab640f7ff |
| hovercard-subject-tag | issue:4411067023 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/JavaScriptSolidServer/JavaScriptSolidServer/389/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bd2c134b87d66e73e0c102c8906966335a49d1f1e2e06a3870d1ec41821eb9c0/JavaScriptSolidServer/JavaScriptSolidServer/issues/389 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bd2c134b87d66e73e0c102c8906966335a49d1f1e2e06a3870d1ec41821eb9c0/JavaScriptSolidServer/JavaScriptSolidServer/issues/389 |
| og:image:alt | Surfaced during #388 (Phase A of #386). Symptom JSON-LD documents with @context in array form (e.g. [ "https://www.w3.org/ns/cid/v1", { ...inline prefixes... } ]) lose all term expansion when conve... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | melvincarvalho |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/JavaScriptSolidServer/JavaScriptSolidServer git https://github.com/JavaScriptSolidServer/JavaScriptSolidServer.git |
| octolytics-dimension-user_id | 205442424 |
| octolytics-dimension-user_login | JavaScriptSolidServer |
| octolytics-dimension-repository_id | 958025407 |
| octolytics-dimension-repository_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 958025407 |
| octolytics-dimension-repository_network_root_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width