diff --git a/gradle.properties b/gradle.properties index 46ec997..6845d83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.1-SNAPSHOT +version=1.0.1-SNAPSHOT diff --git a/src/main/java/com/github/tonivade/resp/protocol/RedisParser.java b/src/main/java/com/github/tonivade/resp/protocol/RedisParser.java index 111925d..4696122 100644 --- a/src/main/java/com/github/tonivade/resp/protocol/RedisParser.java +++ b/src/main/java/com/github/tonivade/resp/protocol/RedisParser.java @@ -82,23 +82,23 @@ private RedisToken parseIntegerToken(SafeString line) { } private RedisToken parseStringToken(SafeString line) { - StringRedisToken token; int length = line.parseIntAfterPrefix(); if (length >= 0 && length < maxLength) { - token = new StringRedisToken(source.readString(length)); - } else { - token = new StringRedisToken(SafeString.EMPTY_STRING); + return new StringRedisToken(source.readString(length)); } - return token; + return new StringRedisToken(SafeString.EMPTY_STRING); } private RedisToken parseArray(int size) { - List array = new ArrayList<>(size); + if (size >= 0 && size < maxLength) { + List array = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - array.add(parseToken(source.readLine())); - } + for (int i = 0; i < size; i++) { + array.add(parseToken(source.readLine())); + } - return array(array); + return array(array); + } + return array(); } } diff --git a/src/test/java/com/github/tonivade/resp/protocol/RedisParserTest.java b/src/test/java/com/github/tonivade/resp/protocol/RedisParserTest.java index ba938ce..bb96967 100644 --- a/src/test/java/com/github/tonivade/resp/protocol/RedisParserTest.java +++ b/src/test/java/com/github/tonivade/resp/protocol/RedisParserTest.java @@ -6,6 +6,7 @@ import com.github.tonivade.resp.protocol.AbstractRedisToken.UnknownRedisToken; import com.github.tonivade.resp.util.StringRedisSource; + import org.junit.jupiter.api.Test; import static com.github.tonivade.resp.protocol.SafeString.safeString; @@ -46,6 +47,15 @@ void testEmptyBulkString() { assertThat(source.available(), equalTo(0)); } + @Test + void testLargeBulkString() { + source.init("$100000\r\n\r\n"); + + RedisToken token = parser.next(); + + assertThat(token, equalTo(emptyString)); + } + @Test void testSimpleString() { source.init("+pong\r\n"); @@ -100,4 +110,18 @@ void testArray() { assertThat(token, equalTo(arrayToken)); assertThat(source.available(), equalTo(0)); } + + @Test + void testLargeArray() throws Exception { + source.init( + "*100000\r\n", + ":1\r\n", + "$3\r\n", + "abc\r\n" + ); + + RedisToken token = parser.next(); + + assertThat(token, equalTo(RedisToken.array())); + } }