Skip to content

Copy @direction when cloning the active context - #587

Open
skydudie wants to merge 1 commit into
digitalbazaar:mainfrom
skydudie:fix-direction-inheritance
Open

skydudie wants to merge 1 commit into
digitalbazaar:mainfrom
skydudie:fix-direction-inheritance

Conversation

@skydudie

@skydudie skydudie commented Sep 13, 2026

Copy link
Copy Markdown

Fixes #586.

What

_cloneActiveContext copies @base, @language, and @vocab onto the child context but not @direction, so the default base direction is silently dropped whenever a context layer is processed on top of an existing active context — a second document-level @context layer, a property-/type-scoped context, an embedded node @context, or a remote context. The default language is inherited correctly in all of those cases; only @direction is lost. Per JSON-LD 1.1 API Context Processing step 1, processing starts from a clone of the active context, whose definition includes the optional default base direction, and step 5.8 only modifies it when the context has a @direction entry.

This PR adds the missing copy, mirroring the @language handling. Explicitly setting or clearing @direction in a layer already worked; only inheritance was broken.

Tests

  • Three regression tests in tests/misc.js (@direction inheritance): survival across document-level layers, inheritance into a property-scoped context, and scoped override / null reset still working.
  • The W3C suites have no fixture covering inheritance of @direction across layers (presumably why this went unnoticed), so local tests it is; happy to propose a json-ld-api suite test separately if useful.
  • Full local run (npm test, with all four fetched suites): same results as unpatched main apart from the three new passing tests — the two fromRdf useNativeTypes failures (#t0027/#t0028) fail identically on unpatched main and are unrelated.

Compatibility note

Because jsonld-signatures defaults rdfDirection: 'i18n-datatype', this changes canonical N-Quads (and therefore RDFC hashes / proof values) for signed documents that combine a default @direction with multiple context layers or scoped contexts. Flagging for your versioning call. Related: w3c/vc-data-integrity#366.

PyLD has the identical omission in _clone_active_context; companion issue digitalbazaar/pyld#337 and matching PR digitalbazaar/pyld#338.

The default base direction is part of the active context (JSON-LD 1.1
API, Context Processing) and must survive cloning like the default
language does. Previously any context layer processed on top of an
existing active context - a second document-level layer, a scoped
context, an embedded node context, or a remote context - silently
dropped the inherited @direction while @language survived.

Fixes digitalbazaar#586.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default @direction is not inherited across context layers — _cloneActiveContext omits @direction

1 participant