You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/11/11 16:50:56 UTC
[8/8] mina-sshd git commit: [SSHD-861] Fixed bug in
NumberUtils#isIntegerNumber
[SSHD-861] Fixed bug in NumberUtils#isIntegerNumber
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/005ee40c
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/005ee40c
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/005ee40c
Branch: refs/heads/master
Commit: 005ee40c0ac8deb148e7e11fe772d4a449be4c0c
Parents: c64bd7a
Author: Lyor Goldstein <lg...@apache.org>
Authored: Sun Nov 11 08:33:56 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Sun Nov 11 18:56:28 2018 +0200
----------------------------------------------------------------------
.../apache/sshd/common/util/NumberUtils.java | 4 ++--
.../sshd/common/util/NumberUtilsTest.java | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/005ee40c/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java b/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
index c8e1817..444113f 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/util/NumberUtils.java
@@ -290,8 +290,8 @@ public final class NumberUtils {
return false;
}
- for (int index = 0; index < cs.length(); index++) {
- char c = cs.charAt(0);
+ for (int index = 0, len = cs.length(); index < len; index++) {
+ char c = cs.charAt(index);
if ((c >= '0') && (c <= '9')) {
continue;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/005ee40c/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java b/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
index 927cecb..d7c2d32 100644
--- a/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
+++ b/sshd-common/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java
@@ -74,4 +74,24 @@ public class NumberUtilsTest extends JUnitTestSupport {
}
}
}
+
+ @Test
+ public void testIsValidIntegerNumber() {
+ for (String s : new String[]{"7", "73", "736", "7365", "19650307"}) {
+ assertTrue(s, NumberUtils.isIntegerNumber(s));
+
+ String pos = "+" + s;
+ assertTrue(pos, NumberUtils.isIntegerNumber(pos));
+
+ String neg = "-" + s;
+ assertTrue(neg, NumberUtils.isIntegerNumber(neg));
+ }
+ }
+
+ @Test
+ public void testIsInvalidIntegerNumber() {
+ for (String s : new String[]{null, "", " ", getCurrentTestName(), "3rd", "3.14", "-.3"}) {
+ assertFalse(s, NumberUtils.isIntegerNumber(s));
+ }
+ }
}