From cf03e6173b70ad64337704402bea51600cddd1ba Mon Sep 17 00:00:00 2001 From: Niall Pemberton Date: Fri, 28 Mar 2014 03:10:27 +0000 Subject: [PATCH] LANG-992 Fix NumberUtils#isNumber() returns false for "0.0", "0.4790", et al git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1582585 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/commons/lang3/math/NumberUtils.java | 3 ++- .../java/org/apache/commons/lang3/math/NumberUtilsTest.java | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java index ee26f2e23..7db1f4e1e 100644 --- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java +++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java @@ -1364,7 +1364,8 @@ public class NumberUtils { } } return true; - } else { // leading 0, but not hex, must be octal + } else if (Character.isDigit(chars[start + 1])) { + // leading 0, but not hex, must be octal int i = start + 1; for (; i < chars.length; i++) { if (chars[i] < '0' || chars[i] > '7') { diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index ea895e256..919020f31 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -1234,6 +1234,12 @@ public class NumberUtilsTest { compareIsNumberWithCreateNumber("00", true); } + @Test + public void testLANG992() { + compareIsNumberWithCreateNumber("0.0", true); + compareIsNumberWithCreateNumber("0.4790", true); + } + @Test public void testLANG972() { compareIsNumberWithCreateNumber("0xABCD", true);