Skip to content

fix(jsonschema): emit unicode-safe patterns from concerto regexes - #301

Open
rishabhknowss wants to merge 1 commit into
accordproject:mainfrom
rishabhknowss:fix/jsonschema-unicode-pattern
Open

rishabhknowss wants to merge 1 commit into
accordproject:mainfrom
rishabhknowss:fix/jsonschema-unicode-pattern

Conversation

@rishabhknowss

Copy link
Copy Markdown

Closes #300

JSONSchemaVisitor copied a concerto regex's source straight into pattern. concerto regexes have no u flag, but ajv compiles pattern in unicode mode, so identity escapes like \< (used in agreement.cto) made the generated schema fail with Invalid escape.

Changes

  • add toUnicodeSafePattern(): if the source isn't valid with the u flag, drop backslashes before characters that don't need escaping (they match the same literal either way). \- is kept inside character classes. valid sources are returned unchanged.
  • use it for field/scalar pattern output.
  • verification test now compiles every definition through a $ref, since ajv skips definitions nothing references (this is why agreement passed before). it fails on main with Invalid regular expression: /^[^\<\>]*$/u: Invalid escape and passes with this fix.
  • unit test covering \<\>, \- outside a class, and an already-safe pattern.

Flags

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

🤖 Generated with Claude Code

Concerto regexes have no `u` flag, so their source may contain identity
escapes such as `\<` that are invalid in unicode mode, which JSON Schema
validators such as ajv use to compile `pattern`. Drop those redundant
escapes when the source is not valid in unicode mode.

Also compile every definition in the JSON Schema verification test, since
ajv only compiles definitions that are referenced.

Closes accordproject#300

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: rishabhknowss <rishabhrai1515@gmail.com>

This branch has not been deployed

No deployments
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.

json schema pattern from concerto regex fails in ajv (unicode mode)

1 participant