Skip to content
Snippets Groups Projects
Commit af1ee7d5 authored by srosse's avatar srosse
Browse files

OO-1038: restraints character boundaries

parent 77978dfd
No related branches found
No related tags found
No related merge requests found
...@@ -404,7 +404,7 @@ public class StringHelper { ...@@ -404,7 +404,7 @@ public class StringHelper {
char[] charArr = string.toCharArray(); char[] charArr = string.toCharArray();
for(int i=charArr.length; i-->stop; ) { for(int i=charArr.length; i-->stop; ) {
char ch = charArr[i]; char ch = charArr[i];
if(ch < 47 || ch > 58) { if(ch < 48 || ch > 57) {
return false; return false;
} }
} }
......
...@@ -112,12 +112,20 @@ public class StringHelperTest { ...@@ -112,12 +112,20 @@ public class StringHelperTest {
@Test @Test
public void isLong() { public void isLong() {
Assert.assertTrue(StringHelper.isLong("234")); Assert.assertTrue(StringHelper.isLong("234"));
Assert.assertTrue(StringHelper.isLong("0123456789"));
Assert.assertTrue(StringHelper.isLong("9223372036854775807")); Assert.assertTrue(StringHelper.isLong("9223372036854775807"));
Assert.assertTrue(StringHelper.isLong("-9223372036854775807")); Assert.assertTrue(StringHelper.isLong("-9223372036854775807"));
//check some unacceptable strings
Assert.assertFalse(StringHelper.isLong("10223372036854775807")); Assert.assertFalse(StringHelper.isLong("10223372036854775807"));
Assert.assertFalse(StringHelper.isLong("-dru")); Assert.assertFalse(StringHelper.isLong("-dru"));
Assert.assertFalse(StringHelper.isLong("OpenOLAT")); Assert.assertFalse(StringHelper.isLong("OpenOLAT"));
Assert.assertFalse(StringHelper.isLong("A very long number with a lot of characters")); Assert.assertFalse(StringHelper.isLong("A very long number with a lot of characters"));
//check ascii range
Assert.assertFalse(StringHelper.isLong("/"));
Assert.assertFalse(StringHelper.isLong(":"));
Assert.assertFalse(StringHelper.isLong("."));
Assert.assertFalse(StringHelper.isLong(";"));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment