Skip to content

Commit

Permalink
Only flip BigDecimal exponent if > 0, under assumption it was encoded…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
msqr committed Dec 16, 2019
1 parent ff60ae5 commit 5d1e99f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,11 @@ protected JsonToken _handleTaggedArray(int tag, int len) throws IOException
_reportError("Unexpected token ("+currentToken()+") as the first part of 'bigfloat' value: should get VALUE_NUMBER_INT");
}
// 27-Nov-2019, tatu: As per [dataformats-binary#139] need to change sign here
int exp = -getIntValue();
// if decoding CBOR generated < v2.10
int exp = getIntValue();
if ( exp < 0 ) {
exp = -exp;
}

// Should get an integer value; int/long/BigInteger
if (!_checkNextIsIntInArray("bigfloat")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,21 @@ public void testBigDecimalType2() throws IOException {
assertNull(parser.nextToken());
}
}

public void testBigDecimalType3() throws IOException {
// Maintain backwards compatibility with < v2.10 where generated CBOR
// affected by [dataformats#139]
final byte[] spec = new byte[] {
(byte) 0xC4, // tag 4
(byte) 0x82, // Array of length 2
0x02, // int -- 2 (should have been 0x21 for -2)
0x19, 0x6a, (byte) 0xb3 // int 27315
};
try (CBORParser parser = cborParser(spec)) {
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextToken());
assertEquals(NumberType.BIG_DECIMAL, parser.getNumberType());
assertEquals(new BigDecimal("273.15"), parser.getDecimalValue());
assertNull(parser.nextToken());
}
}
}

0 comments on commit 5d1e99f

Please sign in to comment.