diff --git a/pom.xml b/pom.xml index fc6ac2909..0bb469425 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.baidu.hugegraph hugegraph-common - 1.6.10 + 1.6.11 hugegraph-common https://github.com/hugegraph/hugegraph-common @@ -212,7 +212,7 @@ - 1.6.10.0 + 1.6.11.0 diff --git a/src/main/java/com/baidu/hugegraph/util/LongEncoding.java b/src/main/java/com/baidu/hugegraph/util/LongEncoding.java index 87b1366fa..4456cf517 100644 --- a/src/main/java/com/baidu/hugegraph/util/LongEncoding.java +++ b/src/main/java/com/baidu/hugegraph/util/LongEncoding.java @@ -70,11 +70,15 @@ public static long decodeSortable(String str) { E.checkArgument(str.length() >= 2, "Length of sortable encoded string must be >=2"); boolean negative = str.charAt(0) == NEG; - int prefix = 1; + int lengthPos = 0; if (negative) { - prefix = 2; + lengthPos = 1; } - String encoded = str.substring(prefix); + int length = BASE_SYMBOLS.indexOf(str.charAt(lengthPos)); + E.checkArgument(length == str.length() - lengthPos - 1, + "Can't decode illegal string '%s' with wrong length", + str); + String encoded = str.substring(lengthPos + 1); long value = decode(encoded); if (negative) { value -= FULL_LONG; @@ -82,6 +86,10 @@ public static long decodeSortable(String str) { return value; } + public static boolean validSortableChar(char c) { + return BASE_SYMBOLS.indexOf(c) != -1; + } + public static String encode(long num) { return encode(num, BASE_SYMBOLS); } diff --git a/src/main/java/com/baidu/hugegraph/version/CommonVersion.java b/src/main/java/com/baidu/hugegraph/version/CommonVersion.java index a54b4186b..1a8bddea3 100644 --- a/src/main/java/com/baidu/hugegraph/version/CommonVersion.java +++ b/src/main/java/com/baidu/hugegraph/version/CommonVersion.java @@ -27,5 +27,5 @@ public class CommonVersion { // The second parameter of Version.of() is for all-in-one JAR public static final Version VERSION = Version.of(CommonVersion.class, - "1.6.10"); + "1.6.11"); } diff --git a/src/test/java/com/baidu/hugegraph/unit/util/LongEncodingTest.java b/src/test/java/com/baidu/hugegraph/unit/util/LongEncodingTest.java index 13ca425da..3004d856c 100644 --- a/src/test/java/com/baidu/hugegraph/unit/util/LongEncodingTest.java +++ b/src/test/java/com/baidu/hugegraph/unit/util/LongEncodingTest.java @@ -278,6 +278,29 @@ public void testDecodeSortable() { Assert.assertEquals(Long.MIN_VALUE, valLongMin); } + @Test + public void testDecodeIllegalSortable() { + // Length is 1, actual length is 0 + Assert.assertThrows(IllegalArgumentException.class, () -> { + LongEncoding.decodeSortable("1"); + }); + + // Length is 1, actual length is 2 + Assert.assertThrows(IllegalArgumentException.class, () -> { + LongEncoding.decodeSortable("123"); + }); + + // Length is 1, actual length is 0 + Assert.assertThrows(IllegalArgumentException.class, () -> { + LongEncoding.decodeSortable("01"); + }); + + // Length is 1, actual length is 2 + Assert.assertThrows(IllegalArgumentException.class, () -> { + LongEncoding.decodeSortable("0123"); + }); + } + @Test public void testEncodeNumber() throws ParseException { String l1234 = LongEncoding.encodeNumber(1234);