Skip to content

Commit 5d1e99f

Browse files
committed
Only flip BigDecimal exponent if > 0, under assumption it was encoded by CBOR generator < v2.10 with bug FasterXML#139. Assumes all generated BigDecimal values had negative exponents to begin with so not generally applicable to community at large.
1 parent ff60ae5 commit 5d1e99f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,11 @@ protected JsonToken _handleTaggedArray(int tag, int len) throws IOException
882882
_reportError("Unexpected token ("+currentToken()+") as the first part of 'bigfloat' value: should get VALUE_NUMBER_INT");
883883
}
884884
// 27-Nov-2019, tatu: As per [dataformats-binary#139] need to change sign here
885-
int exp = -getIntValue();
885+
// if decoding CBOR generated < v2.10
886+
int exp = getIntValue();
887+
if ( exp < 0 ) {
888+
exp = -exp;
889+
}
886890

887891
// Should get an integer value; int/long/BigInteger
888892
if (!_checkNextIsIntInArray("bigfloat")) {

cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/ParserNumbersTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,21 @@ public void testBigDecimalType2() throws IOException {
361361
assertNull(parser.nextToken());
362362
}
363363
}
364+
365+
public void testBigDecimalType3() throws IOException {
366+
// Maintain backwards compatibility with < v2.10 where generated CBOR
367+
// affected by [dataformats#139]
368+
final byte[] spec = new byte[] {
369+
(byte) 0xC4, // tag 4
370+
(byte) 0x82, // Array of length 2
371+
0x02, // int -- 2 (should have been 0x21 for -2)
372+
0x19, 0x6a, (byte) 0xb3 // int 27315
373+
};
374+
try (CBORParser parser = cborParser(spec)) {
375+
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken());
376+
assertEquals(NumberType.BIG_DECIMAL, parser.getNumberType());
377+
assertEquals(new BigDecimal("273.15"), parser.getDecimalValue());
378+
assertNull(parser.nextToken());
379+
}
380+
}
364381
}

0 commit comments

Comments
 (0)