commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang NumberUtilsTest.java
Date Sun, 08 Jun 2003 14:14:01 GMT
scolebourne    2003/06/08 07:14:01

  Modified:    lang/src/java/org/apache/commons/lang NumberUtils.java
               lang/src/test/org/apache/commons/lang NumberUtilsTest.java
  Log:
  Fix bug in NumberUtils where '12a' was treated as a number.
  bug 20538, reported/fix by Eric Pugh/Phil Steitz
  
  Revision  Changes    Path
  1.10      +5 -1      jakarta-commons/lang/src/java/org/apache/commons/lang/NumberUtils.java
  
  Index: NumberUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/NumberUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- NumberUtils.java	8 Jun 2003 14:09:36 -0000	1.9
  +++ NumberUtils.java	8 Jun 2003 14:14:01 -0000	1.10
  @@ -62,6 +62,8 @@
    * @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$
    */
  @@ -763,6 +765,8 @@
                   // 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
  
  
  
  1.7       +26 -2     jakarta-commons/lang/src/test/org/apache/commons/lang/NumberUtilsTest.java
  
  Index: NumberUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/NumberUtilsTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NumberUtilsTest.java	21 May 2003 23:49:15 -0000	1.6
  +++ NumberUtilsTest.java	8 Jun 2003 14:14:01 -0000	1.7
  @@ -65,6 +65,9 @@
    *
    * @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
    * @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
  + * @author Eric Pugh
  + * @author Phil Steitz
  + * @author Stephen Colebourne
    * @version $Id$
    */
   public class NumberUtilsTest extends TestCase {
  @@ -493,13 +496,34 @@
           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;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message