LANG-972 NumberUtils#isNumber does not allow for hex 0XABCD
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1566963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
159415855d
commit
5a509030a9
|
@ -22,6 +22,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.3" date="TBA" description="Bugfix and Feature release">
|
<release version="3.3" date="TBA" description="Bugfix and Feature release">
|
||||||
|
<action issue="LANG-972" type="fix" dev="sebb">NumberUtils#isNumber does not allow for hex 0XABCD</action>
|
||||||
<action issue="LANG-969" type="fix" dev="ggregory" due-to="Matt Bishop">StringUtils.toEncodedString(byte[], Charset) needlessly throws UnsupportedEncodingException</action>
|
<action issue="LANG-969" type="fix" dev="ggregory" due-to="Matt Bishop">StringUtils.toEncodedString(byte[], Charset) needlessly throws UnsupportedEncodingException</action>
|
||||||
<action issue="LANG-970" type="add" dev="ggregory">Add APIs MutableBoolean setTrue() and setFalse()</action>
|
<action issue="LANG-970" type="add" dev="ggregory">Add APIs MutableBoolean setTrue() and setFalse()</action>
|
||||||
<action issue="LANG-946" type="fix" dev="britter">ConstantInitializerTest fails when building with IBM JDK 7</action>
|
<action issue="LANG-946" type="fix" dev="britter">ConstantInitializerTest fails when building with IBM JDK 7</action>
|
||||||
|
|
|
@ -1345,7 +1345,13 @@ public static boolean isNumber(final String str) {
|
||||||
boolean foundDigit = false;
|
boolean foundDigit = false;
|
||||||
// deal with any possible sign up front
|
// deal with any possible sign up front
|
||||||
final int start = (chars[0] == '-') ? 1 : 0;
|
final int start = (chars[0] == '-') ? 1 : 0;
|
||||||
if (sz > start + 1 && chars[start] == '0' && chars[start + 1] == 'x') {
|
if (sz > start + 1 && chars[start] == '0'
|
||||||
|
&&
|
||||||
|
(
|
||||||
|
(chars[start + 1] == 'x') ||
|
||||||
|
(chars[start + 1] == 'X')
|
||||||
|
)
|
||||||
|
) {
|
||||||
int i = start + 2;
|
int i = start + 2;
|
||||||
if (i == sz) {
|
if (i == sz) {
|
||||||
return false; // str == "0x"
|
return false; // str == "0x"
|
||||||
|
|
|
@ -1225,6 +1225,12 @@ public void testIsNumber() {
|
||||||
compareIsNumberWithCreateNumber("1.1L", false); // LANG-664
|
compareIsNumberWithCreateNumber("1.1L", false); // LANG-664
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLANG972() {
|
||||||
|
compareIsNumberWithCreateNumber("0xABCD", true);
|
||||||
|
compareIsNumberWithCreateNumber("0XABCD", true);
|
||||||
|
}
|
||||||
|
|
||||||
private void compareIsNumberWithCreateNumber(final String val, final boolean expected) {
|
private void compareIsNumberWithCreateNumber(final String val, final boolean expected) {
|
||||||
final boolean isValid = NumberUtils.isNumber(val);
|
final boolean isValid = NumberUtils.isNumber(val);
|
||||||
final boolean canCreate = checkCreateNumber(val);
|
final boolean canCreate = checkCreateNumber(val);
|
||||||
|
|
Loading…
Reference in New Issue