Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,7 @@ private boolean checkCode(final String code) {
* code, otherwise {@code false}.
*/
public boolean isValid(final String code) {
final boolean valid = VALIDATOR.isValid(code);
if (valid && checkCountryCode) {
return checkCode(code.substring(0, 2));
}
return valid;
return validate(code) != null;
}

/**
Expand All @@ -476,7 +472,7 @@ public boolean isValid(final String code) {
public Object validate(final String code) {
final Object validate = VALIDATOR.validate(code);
if (validate != null && checkCountryCode) {
return checkCode(code.substring(0, 2)) ? validate : null;
return checkCode(validate.toString().substring(0, 2)) ? validate : null;
}
return validate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
*/
package org.apache.commons.validator.routines;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Tests {@link ISINValidator}.
Expand Down Expand Up @@ -110,4 +113,15 @@ void testIsValidTrue() {
}
}

@ParameterizedTest
@ValueSource(strings = { " US0378331005", "US0378331005 ", " US0378331005 " })
void testValidWithSurroundingWhitespaceCountryCode(final String code) {
// 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.
assertTrue(VALIDATOR_FALSE.isValid(code), code);
assertTrue(VALIDATOR_TRUE.isValid(code), code);
assertEquals("US0378331005", VALIDATOR_TRUE.validate(code), code);
}

}
Loading