Author: britter
Date: Thu Jan 1 16:40:05 2015
New Revision: 1648876
URL: http://svn.apache.org/r1648876
Log:
VALIDATOR-345: ISINCheckDigit fails to reject invalid (non-numeric) check
digits. Fix implemented by Sebb.
Modified:
commons/proper/validator/trunk/RELEASE-NOTES.txt
commons/proper/validator/trunk/src/changes/changes.xml
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java
Modified: commons/proper/validator/trunk/RELEASE-NOTES.txt
URL:
http://svn.apache.org/viewvc/commons/proper/validator/trunk/RELEASE-NOTES.txt?rev=1648876&r1=1648875&r2=1648876&view=diff
==============================================================================
--- commons/proper/validator/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/validator/trunk/RELEASE-NOTES.txt Thu Jan 1 16:40:05 2015
@@ -60,6 +60,8 @@ BUGS FROM PREVIOUS RELEASE
* [VALIDATOR-331] - IBANCheckDigitTest.createInvalidCodes(String[] codes) uses
wrong values.
* [VALIDATOR-336] - CUSIPCheckDigit thinks invalid CUSIP is valid.
+ * [VALIDATOR-345] - ISINCheckDigit fails to reject invalid (non-numeric) check
+ digits
* [VALIDATOR-347] - toLowerCase() method is Locale-sensitive and should not be
used
* [VALIDATOR-348] - Update TLD list to latest version (Version 2014123000)
Modified: commons/proper/validator/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/changes/changes.xml?rev=1648876&r1=1648875&r2=1648876&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Thu Jan 1 16:40:05
2015
@@ -43,6 +43,9 @@ The <action> type attribute can be add,u
<body>
<release version="1.4.1" date="tba" description="1.4 Maintenance release">
+ <action issue="VALIDATOR-345" dev="sebb" type="fix" >
+ ISINCheckDigit fails to reject invalid (non-numeric) check digits
+ </action>
<action issue="VALIDATOR-336" dev="sebb" type="fix" >
CUSIPCheckDigit thinks invalid CUSIP is valid
</action>
Modified:
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
URL:
http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java?rev=1648876&r1=1648875&r2=1648876&view=diff
==============================================================================
---
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
(original)
+++
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigit.java
Thu Jan 1 16:40:05 2015
@@ -67,12 +67,20 @@ public final class ISINCheckDigit extend
*/
protected int calculateModulus(String code, boolean includesCheckDigit)
throws CheckDigitException {
StringBuffer transformed = new StringBuffer(code.length() * 2);
+ if (includesCheckDigit) {
+ char checkDigit = code.charAt(code.length()-1); // fetch the last
character
+ if (!Character.isDigit(checkDigit)){
+ throw new CheckDigitException("Invalid checkdigit["+
checkDigit+ "] in " + code);
+ }
+ }
for (int i = 0; i < code.length(); i++) {
int charValue = Character.getNumericValue(code.charAt(i));
if (charValue < 0 || charValue > 35) {
throw new CheckDigitException("Invalid Character[" +
(i + 1) + "] = '" + charValue + "'");
}
+ // this converts alphanumerics to two digits
+ // so there is no need to overload toInt()
transformed.append(charValue);
}
return super.calculateModulus(transformed.toString(),
includesCheckDigit);
Modified:
commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java?rev=1648876&r1=1648875&r2=1648876&view=diff
==============================================================================
---
commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java
(original)
+++
commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java
Thu Jan 1 16:40:05 2015
@@ -48,4 +48,20 @@ public class ISINCheckDigitTest extends
};
invalid = new String[] {"0378#3100"};
}
+
+ private static String invalidCheckDigits[] =
+ {"US037833100O", // proper check digit is '5',
see above
+ "BMG8571G109D", // proper check digit is '6',
see above
+ "AU0000XVGZAD", // proper check digit is '3',
see above
+ "GB000263494I", // proper check digit is '6',
see above
+ "FR000402625C", // proper check digit is '0',
see above
+ "DK000976334H", // proper check digit is '4',
see above
+ };
+
+ public void testVALIDATOR_345() {
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ String invalidCheckDigit = invalidCheckDigits[i];
+ assertFalse("Should fail: " + invalidCheckDigit,
routine.isValid(invalidCheckDigit));
+ }
+ }
}