Fix state leakage of otherCountryCodes in IBANValidator custom configurations#382
Open
sahvx655-wq wants to merge 1 commit into
Open
Fix state leakage of otherCountryCodes in IBANValidator custom configurations#382sahvx655-wq wants to merge 1 commit into
sahvx655-wq wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a state consistency issue in mutable
IBANValidatorinstances where associated territory codes (otherCountryCodes) could remain mapped to obsolete validator instances after a validator was removed or replaced.Some validators define additional territory codes through
otherCountryCodes(for example,FRincludesGF,GP,MQ, etc., andGBincludesIM,JE,GG).When
setValidator(...)was used to remove or replace a validator, the implementation updated only the primarycountryCodeentry invalidatorMap. Any entries created forotherCountryCodeswere left untouched.As a result, territory codes could continue resolving to a stale validator that was no longer registered, causing inconsistent validation behavior and leaving
validatorMapin an incorrect state.The validator update logic has been extended to keep all related mappings synchronized:
When a validator is removed, any associated
otherCountryCodesmappings are removed as well.When a validator is replaced, mappings belonging to the previous validator are cleaned up before registering the new validator and its associated territory codes.
The internal
validatorMapnow remains consistent after validator additions, replacements, and removals.Added regression tests in
IBANValidatorTestcovering:Removal of a validator with associated
otherCountryCodesReplacement of a validator with associated
otherCountryCodesVerification that stale territory-code mappings are properly cleaned up
Verification that new territory-code mappings are correctly registered