Skip to content

Fixed regexrule and timezonerule inconsistencies#3

Merged
sn merged 1 commit into
mainfrom
chore/regex-rule-leaks
May 17, 2026
Merged

Fixed regexrule and timezonerule inconsistencies#3
sn merged 1 commit into
mainfrom
chore/regex-rule-leaks

Conversation

@sn
Copy link
Copy Markdown
Contributor

@sn sn commented May 17, 2026

This pull request makes several improvements and fixes to the nitro_validator package, focusing on validator instance isolation, rule parsing, and increased robustness of built-in rules. The most significant change is that each NitroValidator instance now gets its own independent rule registry by default, preventing rule registrations from leaking across instances. Additionally, the built-in rules are improved for correctness and clarity, and the handling of custom error messages is made safer.

Validator instance isolation and registry handling:

  • Each NitroValidator now receives a fresh copy of the built-in rule registry by default, so custom rules registered on one validator do not affect others. The registry is copied using a new copy() method on NitroRuleRegistry. [1] [2] [3]

Rule parsing and error handling:

  • Improved error handling and documentation for rule string parsing, clarifying that pipe (|) and comma (,) characters cannot appear in rule arguments, and that rules needing such patterns (like regexes) must be passed as instances. [1] [2]
  • The RegexRule now compiles its pattern at initialization, and fails validation if the pattern is invalid or missing.

Built-in rule improvements and bug fixes:

  • The IpRule now uses precompiled patterns for IPv4 and IPv6, and checks both correctly. [1] [2]
  • All numeric rules (MinRule, MaxRule, BetweenRule, PositiveRule, NegativeRule) now explicitly reject boolean values, which previously could be incorrectly accepted as numbers. [1] [2] [3] [4] [5] [6] [7]

Custom error message handling:

  • Custom error messages for rules are now applied in a way that prevents them from leaking between validations, by temporarily overriding the rule's custom_message attribute.

Documentation and minor cleanups:

  • Various docstring and comment improvements for clarity and accuracy, including details on rule syntax and usage. [1] [2] [3] [4] [5] [6]

These changes improve the reliability, safety, and clarity of the validation framework.

@sn sn self-assigned this May 17, 2026
@sn sn merged commit 0e9a13c into main May 17, 2026
6 checks passed
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.

1 participant