Fix ISIN country-code check using untrimmed input#399
Open
sahvx655-wq wants to merge 2 commits into
Open
Conversation
garydgregory
requested changes
Jun 15, 2026
| // The underlying CodeValidator trims the input, so the country code must be | ||
| // derived from the trimmed code. Otherwise a valid ISIN with leading whitespace | ||
| // is accepted without the country check but rejected with it. | ||
| final String leading = " US0378331005"; |
Member
There was a problem hiding this comment.
How about trailing whitespace?
Contributor
Author
There was a problem hiding this comment.
Trailing whitespace is handled the same way. CodeValidator.validate trims both ends before matching, and since the fix now reads the country code from the validated/trimmed value rather than the raw argument, the substring(0, 2) lookup sees "US" regardless of where the whitespace sits.
I have extended the regression test to loop over leading, trailing and surrounding whitespace so all three paths are covered. Full ISINValidatorTest still passes (Tests run: 5, Failures: 0).
garydgregory
requested changes
Jun 16, 2026
garydgregory
left a comment
Member
There was a problem hiding this comment.
@sahvx655-wq
Please see my comment.
TY.
| // The underlying CodeValidator trims the input, so the country code must be | ||
| // derived from the trimmed code. Otherwise a valid ISIN with surrounding whitespace | ||
| // is accepted without the country check but rejected with it. | ||
| for (final String code : new String[] { " US0378331005", "US0378331005 ", " US0378331005 " }) { |
Member
There was a problem hiding this comment.
Use @ParameterizedTest instead of a loop.
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.
ISIN country code read from the raw argument
Whilst checking the country-code path I noticed that
isValid/validatedisagree with the underlyingCodeValidatorfor inputs with surrounding whitespace. The validator trims the argument before matching, sovalidate(" US0378331005")returns the trimmedUS0378331005, but the ISO-3166 lookup then takescode.substring(0, 2)from the original untrimmed string and reads" U", which is not a country code. The upshot is that the same valid ISIN passes withgetInstance(false)yet is rejected bygetInstance(true).The root cause is the country code being derived from the raw argument rather than from the code the validator actually accepted. Reading it from the validated value keeps both code paths consistent. Left unfixed, callers that enable the country check silently reject otherwise-valid codes purely on the presence of leading whitespace. Added a regression test for the trimmed lookup.