Skip to content

format: align pointer identifier and contract type guards with their schemas#276

Open
gnidan wants to merge 2 commits into
mainfrom
debugger-isidentifier-regex
Open

format: align pointer identifier and contract type guards with their schemas#276
gnidan wants to merge 2 commits into
mainfrom
debugger-isidentifier-regex

Conversation

@gnidan

@gnidan gnidan commented Jul 24, 2026

Copy link
Copy Markdown
Member

Two format-package type guards had drifted from the schemas they mirror.

Pointer.isIdentifier

The guard copied the identifier schema's regex with its YAML escaping intact. In schemas/pointer/identifier.schema.yaml the character classes are written [a-zA-Z_\\-] / [a-zA-Z0-9$_\\-], where the doubled backslash is YAML escaping for a single backslash that, in the regex, escapes the hyphen. Copied verbatim into a JavaScript regex literal, \\- no longer means "escaped hyphen" — it matches a literal backslash. The guard therefore accepted identifiers containing backslashes (e.g. "foo\bar") that the schema rejects.

The fix drops the extra backslash so the classes match the schema exactly (a plain trailing hyphen, literal in that position).

Type.Elementary.isContract

The contract type schema uses a oneOf to distinguish normal, library, and interface contract types through the library and interface boolean flags, but the Contract interface and guard dropped both flags. The guard accepted a contract that sets both flags true — a shape the schema rejects, since it satisfies two oneOf branches at once — and the interface lost the three-way distinction.

The fix adds the flags to the interface and the guard, validating each as a boolean when present and rejecting the both-true shape, matching the current schema semantics. (Tightening the schema's own flag typing is tracked separately.)

Tests

Both guards gain coverage that asserts guard/schema agreement, so they cannot silently drift again:

  • identifier: the schema examples via the shared testSchemaGuards harness, plus a corpus checked against the pattern read directly from the schema (backslash strings rejected, valid identifiers accepted).
  • contract: the three legal shapes and the both-true rejection, each checked against the guard and validated against the schema.

The `isIdentifier` type guard copied the identifier schema's regex with
its YAML escaping intact. In the schema, `\\-` inside the character
classes decodes to an escaped hyphen; carried verbatim into a JavaScript
regex literal, `\\-` instead matches a literal backslash. The guard
therefore accepted identifiers containing backslashes (e.g. "foo\bar")
that fail the schema.

Drop the extra backslash so the character classes match the schema
exactly, and cover the guard with the identifier schema examples plus a
regression corpus that asserts guard/schema agreement (backslash strings
rejected, valid identifiers accepted).
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://ethdebug.github.io/format/pr-preview/pr-276/

Built to branch gh-pages at 2026-07-24 02:16 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

The contract type schema uses a oneOf to distinguish normal, library,
and interface contract types through the `library` and `interface`
boolean flags, but the `Contract` interface and `isContract` guard
dropped both flags. The guard accepted a contract that sets both flags
true — a shape the schema rejects because it satisfies two oneOf
branches at once — and the interface lost the three-way distinction.

Add the flags to the interface and the guard, validating each as a
boolean when present and rejecting the both-true shape, matching the
current schema semantics. Cover the three legal shapes and the both-true
rejection, asserting the guard and the schema agree on each.
@gnidan gnidan changed the title format: align isIdentifier with the identifier schema pattern format: align pointer identifier and contract type guards with their schemas Jul 24, 2026
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.

1 participant