fix: don't throw when @context contains a non-string entry - #514
Merged
Conversation
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.
hkir-dev
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenactiveUrlsCorrectRule assumed every entry in an
@contextarray was a string and called.match()on each one. JSON-LD permits an@contextarray to combine IRIs with inline context definitions (maps), so a conformant-JSON-LD-but-non-conformant-OpenActive feed such as: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
typefailure ("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.