Fix bug in NumberUtils where '12a' was treated as a number.
bug 20538, reported/fix by Eric Pugh/Phil Steitz git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137359 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4c50eca073
commit
4920a1da32
|
@ -62,8 +62,10 @@ import java.math.BigDecimal;
|
|||
* @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
|
||||
* @author Stephen Colebourne
|
||||
* @author <a href="mailto:steve.downey@netfolio.com">Steve Downey</a>
|
||||
* @author Eric Pugh
|
||||
* @author Phil Steitz
|
||||
* @since 1.0
|
||||
* @version $Id: NumberUtils.java,v 1.9 2003/06/08 14:09:36 scolebourne Exp $
|
||||
* @version $Id: NumberUtils.java,v 1.10 2003/06/08 14:14:01 scolebourne Exp $
|
||||
*/
|
||||
public final class NumberUtils {
|
||||
|
||||
|
@ -763,6 +765,8 @@ public final class NumberUtils {
|
|||
// not allowing L with an exponoent
|
||||
return foundDigit && !hasExp;
|
||||
}
|
||||
// last character is illegal
|
||||
return false;
|
||||
}
|
||||
// allowSigns is true iff the val ends in 'E'
|
||||
// found digit it to make sure weird stuff like '.' and '1E-' doesn't pass
|
||||
|
|
|
@ -65,7 +65,10 @@ import junit.framework.TestSuite;
|
|||
*
|
||||
* @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
|
||||
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
|
||||
* @version $Id: NumberUtilsTest.java,v 1.6 2003/05/21 23:49:15 scolebourne Exp $
|
||||
* @author Eric Pugh
|
||||
* @author Phil Steitz
|
||||
* @author Stephen Colebourne
|
||||
* @version $Id: NumberUtilsTest.java,v 1.7 2003/06/08 14:14:01 scolebourne Exp $
|
||||
*/
|
||||
public class NumberUtilsTest extends TestCase {
|
||||
|
||||
|
@ -493,13 +496,34 @@ public class NumberUtilsTest extends TestCase {
|
|||
val = "1234E5l";
|
||||
assertTrue("isNumber(String) 14 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 14 Neg failed", !checkCreateNumber(val));
|
||||
val = "11a";
|
||||
assertTrue("isNumber(String) 15 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 15 Neg failed", !checkCreateNumber(val));
|
||||
val = "1a";
|
||||
assertTrue("isNumber(String) 16 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 16 Neg failed", !checkCreateNumber(val));
|
||||
val = "a";
|
||||
assertTrue("isNumber(String) 17 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 17 Neg failed", !checkCreateNumber(val));
|
||||
val = "11g";
|
||||
assertTrue("isNumber(String) 18 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 18 Neg failed", !checkCreateNumber(val));
|
||||
val = "11z";
|
||||
assertTrue("isNumber(String) 19 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 19 Neg failed", !checkCreateNumber(val));
|
||||
val = "11def";
|
||||
assertTrue("isNumber(String) 20 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 20 Neg failed", !checkCreateNumber(val));
|
||||
val = "11d11";
|
||||
assertTrue("isNumber(String) 21 Neg failed", !NumberUtils.isNumber(val));
|
||||
assertTrue("isNumber(String)/createNumber(String) 21 Neg failed", !checkCreateNumber(val));
|
||||
|
||||
}
|
||||
|
||||
private boolean checkCreateNumber(String val) {
|
||||
try {
|
||||
Object obj = NumberUtils.createNumber(val);
|
||||
if(obj == null) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue