Skip to content

Commit 1baa5c2

Browse files
committed
msgpack#100: Add test cases for FIXEXT. Fix unmappable UTF8 character check
1 parent 1632381 commit 1baa5c2

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,8 @@ public MessagePacker packString(String s) throws IOException {
342342
}
343343

344344
if(cr.isError()) {
345-
if(cr.isMalformed() && config.getActionOnMalFormedInput() == CodingErrorAction.REPORT) {
346-
cr.throwException();
347-
} else if(cr.isUnderflow() && config.getActionOnUnmappableCharacter() == CodingErrorAction.REPORT) {
345+
if((cr.isMalformed() && config.getActionOnMalFormedInput() == CodingErrorAction.REPORT) ||
346+
(cr.isUnmappable() && config.getActionOnUnmappableCharacter() == CodingErrorAction.REPORT)) {
348347
cr.throwException();
349348
}
350349
}

msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,8 @@ public String unpackString() throws IOException {
831831
}
832832

833833
if(cr.isError()) {
834-
if(cr.isMalformed() && config.getActionOnMalFormedInput() == CodingErrorAction.REPORT) {
835-
cr.throwException();
836-
} else if(cr.isUnmappable() && config.getActionOnUnmappableCharacter() == CodingErrorAction.REPORT) {
834+
if((cr.isMalformed() && config.getActionOnMalFormedInput() == CodingErrorAction.REPORT) ||
835+
(cr.isUnmappable() && config.getActionOnUnmappableCharacter() == CodingErrorAction.REPORT)) {
837836
cr.throwException();
838837
}
839838
}

msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MessagePackTest extends MessagePackSpec {
3232

3333
"detect fixint quickly" in {
3434

35-
val N = 10000000
35+
val N = 100000
3636
val idx = (0 until N).map(x => Random.nextInt(256).toByte).toArray[Byte]
3737

3838
time("check fixint", repeat = 100) {
@@ -253,6 +253,13 @@ class MessagePackTest extends MessagePackSpec {
253253
check(ext, _.packExtendedTypeHeader(ext.getType, ext.getLength), _.unpackExtendedTypeHeader())
254254
}
255255
}
256+
257+
val extLen = Seq(1, 2, 4, 8, 16, 1000, 2000, 10000, 50000, 100000, 500000)
258+
for(l <- extLen) {
259+
val ext = new ExtendedTypeHeader(l, Random.nextInt(128))
260+
check(ext, _.packExtendedTypeHeader(ext.getType, ext.getLength), _.unpackExtendedTypeHeader())
261+
}
262+
256263
}
257264

258265
}

0 commit comments

Comments
 (0)