Skip to content

fix(json_schema): keep pattern alternations inside JSON quotes - #268

Open
original4422 wants to merge 1 commit into
dottxt-ai:mainfrom
original4422:fix/267-pattern-alternation
Open

fix(json_schema): keep pattern alternations inside JSON quotes#268
original4422 wants to merge 1 commit into
dottxt-ai:mainfrom
original4422:fix/267-pattern-alternation

Conversation

@original4422

Copy link
Copy Markdown

Summary

JSON Schema string patterns with a top-level alternation were interpolated directly between JSON quote characters. That allowed the alternation to bind across the quotes, rejecting valid values while accepting malformed JSON.

This change wraps the interpolated pattern in a non-capturing group inside the quotes. It preserves user capture numbering while keeping every alternative within the JSON string. The regression test covers unanchored and paired-anchor alternations, malformed missing-quote inputs, a simple pattern, and an already-parenthesized pattern.

Fixes #267

Validation

  • cargo test string_pattern_alternations_stay_inside_json_quotes -- --nocapture
  • cargo test json_schema -- --nocapture
  • cargo test
  • cargo fmt -- --check
  • cargo clippy --all-targets --features python-bindings -- -D warnings
  • Python 3.14: maturin develop
  • Python 3.14: pytest tests/test_json_schema.py tests/test_imports.py -vv (10 passed)
  • Direct Python full-match reproduction accepts both valid alternatives and rejects both malformed missing-quote inputs

pre-commit run --all-files passed every hook except cargo-fmt, which could not start because this host uses Homebrew Cargo without rustup and therefore cannot resolve cargo +nightly. The equivalent stable cargo fmt -- --check passed; the changed code does not involve the repository formatting options that are nightly-only.

Checklist

  • The title describes the change.
  • A high-level description and the relevant issue are included.
  • The branch is based on the latest main commit.
  • The change is one logical commit and follows current naming conventions.
  • Tests cover the regression.
  • No documentation update is needed because the public API is unchanged.

Copilot AI lite review requested due to automatic review settings August 20, 2026 01:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@original4422

Copy link
Copy Markdown
Author

Hi @RobinPicard, when you have a chance, could you please review this PR and let me know if any changes are needed? Thanks!

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.

A pattern with a top-level alternation compiles to a guide that accepts only malformed JSON

2 participants