Skip to content

fix: Show the regex instead of the value in the pattern error message - #974

Merged
DannyvdSluijs merged 1 commit into
jsonrainbow:mainfrom
Roman3349:fix/pattern-error-message
Oct 16, 2026
Merged

DannyvdSluijs merged 1 commit into
jsonrainbow:mainfrom
Roman3349:fix/pattern-error-message

Conversation

@Roman3349

Copy link
Copy Markdown
Contributor

Description

The pattern constraints in Draft-06, Draft-07, and Draft 2019-09 passed found as the first argument to sprintf. As a result, the error message Does not match the regex pattern %s contained the validated value instead of the regex pattern. For example, it produced Does not match the regex pattern invalidpassword instead of Does not match the regex pattern ^[ -~]+$.

The parameters are now passed as ['pattern' => ..., 'found' => ...].

Related Issue

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional Notes

Added a PatternConstraintTest for each of Draft-06, Draft-07 and Draft 2019-09 that checks both the message and the order of the error parameters. The new tests fail without the fix.

The pattern constraints of Draft-06, Draft-07 and Draft 2019-09 passed
"found" as the first error parameter, so the message template
"Does not match the regex pattern %s" was filled with the validated
value instead of the pattern.

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
@DannyvdSluijs
DannyvdSluijs force-pushed the fix/pattern-error-message branch from 2043616 to dbd99dc Compare October 16, 2026 14:21
@DannyvdSluijs
DannyvdSluijs merged commit 13c074e into jsonrainbow:main Oct 16, 2026
18 checks passed
github-actions Bot added a commit that referenced this pull request Oct 16, 2026
@Roman3349
Roman3349 deleted the fix/pattern-error-message branch October 17, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants