format: align pointer identifier and contract type guards with their schemas#276
Open
gnidan wants to merge 2 commits into
Open
format: align pointer identifier and contract type guards with their schemas#276gnidan wants to merge 2 commits into
gnidan wants to merge 2 commits into
Conversation
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).
Contributor
|
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.
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.
Two format-package type guards had drifted from the schemas they mirror.
Pointer.isIdentifierThe guard copied the identifier schema's regex with its YAML escaping intact. In
schemas/pointer/identifier.schema.yamlthe 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.isContractThe contract type schema uses a
oneOfto distinguish normal, library, and interface contract types through thelibraryandinterfaceboolean flags, but theContractinterface and guard dropped both flags. The guard accepted a contract that sets both flags true — a shape the schema rejects, since it satisfies twooneOfbranches 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:
testSchemaGuardsharness, plus a corpus checked against the pattern read directly from the schema (backslash strings rejected, valid identifiers accepted).