← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11396: Fixed bug with isNumeric regex, did not allow values between 0 and -1

 

------------------------------------------------------------
revno: 11396
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-07-15 18:39:13 +0200
message:
  Fixed bug with isNumeric regex, did not allow values between 0 and -1
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2013-06-05 19:48:08 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2013-07-15 16:39:13 +0000
@@ -46,7 +46,7 @@
     
     private static final double TOLERANCE = 0.01; 
     
-    public static final String NUMERIC_REGEXP = "^(0|-?[1-9]\\d*)(\\.\\d+)?$";    
+    public static final String NUMERIC_REGEXP = "^(-?0|-?[1-9]\\d*)(\\.\\d+)?$";
     public static final String NUMERIC_LENIENT_REGEXP = "^(-?[0-9]+)(\\.[0-9]+)?$";
     
     private static final Pattern NUMERIC_PATTERN = Pattern.compile( NUMERIC_REGEXP );

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2013-04-21 18:28:51 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2013-07-15 16:39:13 +0000
@@ -99,6 +99,7 @@
         assertTrue( MathUtils.isNumeric( "1.234" ) );
         assertTrue( MathUtils.isNumeric( "-1234" ) );
         assertTrue( MathUtils.isNumeric( "-12.34" ) );
+        assertTrue( MathUtils.isNumeric( "-0.34" ) );
 
         assertFalse( MathUtils.isNumeric( "Hey" ) );
         assertFalse( MathUtils.isNumeric( "45 Perinatal Condition" ) );
@@ -117,6 +118,10 @@
         assertFalse( MathUtils.isNumeric( "0,1" ) );
         assertFalse( MathUtils.isNumeric( "0," ) );
         assertFalse( MathUtils.isNumeric( "0." ) );
+        assertFalse( MathUtils.isNumeric( "01" ) );
+        assertFalse( MathUtils.isNumeric( "001" ) );
+        assertFalse( MathUtils.isNumeric( "00.23" ) );
+        assertFalse( MathUtils.isNumeric( "01.23" ) );
         assertFalse( MathUtils.isNumeric( null ) );
     }
 
@@ -133,6 +138,7 @@
         assertTrue( MathUtils.isNumericLenient( "1.234" ) );
         assertTrue( MathUtils.isNumericLenient( "-1234" ) );
         assertTrue( MathUtils.isNumericLenient( "-12.34" ) );
+        assertTrue( MathUtils.isNumericLenient( "-0.34" ) );
 
         assertFalse( MathUtils.isNumericLenient( "Hey" ) );
         assertFalse( MathUtils.isNumericLenient( "45 Perinatal Condition" ) );