Skip to content

fix: don't throw when @context contains a non-string entry - #514

Merged
howaskew merged 1 commit into
masterfrom
fix/inline-context-object-crash
Aug 3, 2026
Merged

fix: don't throw when @context contains a non-string entry#514
howaskew merged 1 commit into
masterfrom
fix/inline-context-object-crash

Conversation

@howaskew

Copy link
Copy Markdown
Contributor

OpenactiveUrlsCorrectRule assumed every entry in an @context array was a string and called .match() on each one. JSON-LD permits an @context array to combine IRIs with inline context definitions (maps), so a conformant-JSON-LD-but-non-conformant-OpenActive feed such as:

"@context": ["https://openactive.io/", {"schema": "https://schema.org/"}]

caused TypeError: context.match is not a function. In data-model-validator-site this surfaces to the publisher as an opaque "Internal validator error" with no indication of what is wrong, and no other errors in the document are reported.

The validator already handles this case correctly: ContextInRootNodeRule raises its type failure ("Whilst JSON-LD supports inline context objects, for use in OpenActive the @context property must contain a URL or array of URLs...") for exactly this input. The crash happened before that error could be surfaced.

Non-string entries are now filtered out before the URL check, so the rule inspects only the entries it is able to inspect. Behaviour is otherwise unchanged: incorrect OpenActive URLs are still flagged, including when they appear alongside a non-string entry.

This also fixes the same crash for null, numeric and nested-array entries.

Tests: unit coverage for non-string entries (object, null, number, nested array) in the rule spec, plus an end-to-end regression test in validate-spec asserting that ContextInRootNodeRule reports the failure rather than the run throwing.

OpenactiveUrlsCorrectRule assumed every entry in an `@context` array was a
string and called `.match()` on each one. JSON-LD permits an `@context`
array to combine IRIs with inline context definitions (maps), so a
conformant-JSON-LD-but-non-conformant-OpenActive feed such as:

    "@context": ["https://openactive.io/", {"schema": "https://schema.org/"}]

caused `TypeError: context.match is not a function`. In data-model-validator-site
this surfaces to the publisher as an opaque "Internal validator error" with no
indication of what is wrong, and no other errors in the document are reported.

The validator already handles this case correctly: ContextInRootNodeRule
raises its `type` failure ("Whilst JSON-LD supports inline context objects,
for use in OpenActive the @context property must contain a URL or array of
URLs...") for exactly this input. The crash happened before that error could
be surfaced.

Non-string entries are now filtered out before the URL check, so the rule
inspects only the entries it is able to inspect. Behaviour is otherwise
unchanged: incorrect OpenActive URLs are still flagged, including when they
appear alongside a non-string entry.

This also fixes the same crash for `null`, numeric and nested-array entries.

Tests: unit coverage for non-string entries (object, null, number, nested
array) in the rule spec, plus an end-to-end regression test in validate-spec
asserting that ContextInRootNodeRule reports the failure rather than the run
throwing.
@howaskew
howaskew requested a review from hkir-dev July 31, 2026 15:25
@howaskew
howaskew merged commit a1e1974 into master Aug 3, 2026
11 checks passed
@howaskew
howaskew deleted the fix/inline-context-object-crash branch August 3, 2026 08:38
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.

2 participants