Skip to content

Fix additionalProperties matching with pattern backreferences - #141

Closed
Kaileshwar16 wants to merge 1 commit into
hyperjump-io:mainfrom
Kaileshwar16:fix/138-pattern-backreferences
Closed

Kaileshwar16 wants to merge 1 commit into
hyperjump-io:mainfrom
Kaileshwar16:fix/138-pattern-backreferences

Conversation

@Kaileshwar16

Copy link
Copy Markdown
Contributor

Fixes #138.

additionalProperties combines patternProperties patterns into one regex, which changes capture group numbering. With ^(a)\1$ and ^(b)\1$, this incorrectly rejects bb and accepts
b.

Compile each pattern independently and check literal properties names separately. This preserves backreference behavior and supports validator serialization.

Adds regression coverage across six JSON Schema dialects, including named captures, serialization, and interaction with unevaluatedProperties.

Validation:

  • 107 focused tests passed.
  • 15 new tests fail against the original implementation.
  • Lint and type checks passed.
  • Full suite: 15,020 passed, 64 skipped, and 8 date-time failures. The same eight failures reproduce on the unchanged base.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working on this. Unfortunately, I can't accept this because it changes the compiled value of additionalProperties.

Other packages read the compiled keyword values either through EvaluationPlugins or by working with the AST directly. They expect [RegExp, string], so changing the shape breaks them.

Also, the convention in this repo is to test through the JSON Schema Test Suite. Remove your tests and add them there so everyone gets them.

@Kaileshwar16

Copy link
Copy Markdown
Contributor Author

@jdesrosiers I checked the compatibility issue, and the simpler fixes dont seem reliable. A proper fix might need regex-aware rewriting, which seems like a lot of complexity for this edge case. imo, it might not be worth adding that much complexity. Would you suggest another approach, or should we close this pr for now ?

@jdesrosiers

Copy link
Copy Markdown
Collaborator

I think it's ok to close for now. It's a pretty obscure edge case.

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.

additionalProperties gives incorrect results when patternProperties uses backreferences

2 participants