feat: opt-in validation modes for the parser - #634
Draft
jeswr wants to merge 3 commits into
Draft
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 2, 2026
…ons (rdfjs#666) Extend `validate: { terms: true }` with the two remaining term dimensions: - blank node labels are checked against the `BLANK_NODE_LABEL` rule (including labels formed with the `blankNodePrefix` option; in N3, only the label as written, as scope prefixes use a dot by design) - the base direction of directional language-tagged strings must be `ltr` or `rtl` Both checks are installed as per-instance overrides in the constructor, keeping the default (validation-off) read path untouched. This completes the term dimensions of the opt-in `validate` option. Refs rdfjs#666 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
Author
|
Folded the two remaining term dimensions from #666 (M4 blank-node labels, M5 base direction) into |
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.
Adds an opt-in
validateoption toN3.Parser, as requested in #622 (comment). Refs #622.Design: the option covers the validation dimensions that
formatdoes not already gate.validate: { terms: true }— well-formedness of the terms the grammar produces: IRIs must be absolute and match RFC 3987'sIRIrule (rejecting unresolved relative IRIs,<http://example.org/%ZZ>, …), language tags must be well-formed per BCP 47, literal values ofxsd:boolean|integer|decimal|double|float|date|time|dateTimemust be in their lexical space, blank-node labels must match theBLANK_NODE_LABELproduction (astral-aware), and base directions must beltr/rtl. Lexical checks only — no registry lookups, no value-space rules — implemented internally (src/Validation.js) to keep N3.js dependency-free. (Blank-node labels and base direction were folded in from Validate blank-node labels and literal base directions in opt-in parser validation (#634) #666/M4+M5 in 004d9b3.)validate: { version: true }— profile enforcement composed with the existingversionoption:version: '1.1'rejects triple terms, reified triples, annotation syntax, directional language tags, and version declarations;version: '1.2-basic'rejects triple terms and their sugar (per RDF 1.2 Concepts, Basic excludes only triple terms).validate: trueenables both.Deliberately not covered: RDF/JS interface conformance (the parser constructs terms through its
factory, so that check would only re-test the factory — it belongs at the factory boundary); N3 validity (already whatformat: 'text/n3'does); shape-level validation (separate layer, noted in the #622 docs).Zero cost when off: with
validateabsent the parser runs identical code — validation is installed as per-instance method overrides in the constructor, so no check was added to the default read path. Measured within noise ofmain(a control build with the checks stripped was no faster). Validation on is ~40 % slower on a 200 k-triple parse, dominated by the RFC 3987 regex. The only default-path additions are two guards on rare paths that also fix a latent crash:_completeSubjectLiteralpreviously dereferenced the result of_completeLiteralwithout the undefined check its object-position counterpart has.Reviewer notes on the 004d9b3 additions: (1) in N3 mode only the written
token.valueof a blank-node label is checked (N3 deliberately scopes dot-prefixed internal labels), so a malformedblankNodePrefixis not caught in N3 format specifically — pinned by a regression test; (2) the direction check is defense-in-depth (the built-in lexer only emitsltr/rtl; it bites only for a customoptions.lexer); (3) direction validity is enforced in all versions undervalidate.terms; version-gating of directional tags stays withvalidate.version.Full suite green — 6666 tests, 100 % coverage.
cc @jeswr — design-discussion draft; the option shape (
validate: true/{ terms, version }) and the datatype list are the parts most worth debating.Closes #666