Skip to content

Commit 46f1ac9

Browse files
authored
Merge pull request #114 from philipa/2.9
copyStructure(): avoid duplicate tags when copying tagged binary.
2 parents 9e574c5 + d9ad27c commit 46f1ac9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ protected JsonToken _handleTaggedBinary(int tag) throws IOException
843843
}
844844
_numberBigInt = nr;
845845
_numTypesValid = NR_BIGINT;
846+
_tagValue = -1;
846847
return (_currToken = JsonToken.VALUE_NUMBER_INT);
847848
}
848849

cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/GeneratorSimpleTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.*;
44
import java.math.BigDecimal;
5+
import java.math.BigInteger;
56
import java.util.*;
67

78
import org.junit.Assert;
@@ -398,7 +399,7 @@ public void testCopyCurrentEventWithTag() throws Exception {
398399
targetBytes.toByteArray());
399400
}
400401

401-
public void testCopyCurrentSturctureWithTag() throws Exception {
402+
public void testCopyCurrentStructureWithTaggedArray() throws Exception {
402403
final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream();
403404
final CBORGenerator sourceGen = cborGenerator(sourceBytes);
404405
sourceGen.writeNumber(BigDecimal.ONE);
@@ -422,4 +423,24 @@ public void testCopyCurrentSturctureWithTag() throws Exception {
422423
},
423424
targetBytes.toByteArray());
424425
}
426+
427+
428+
public void testCopyCurrentStructureWithTaggedBinary() throws Exception {
429+
final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream();
430+
final CBORGenerator sourceGen = cborGenerator(sourceBytes);
431+
sourceGen.writeNumber(BigInteger.ZERO);
432+
sourceGen.close();
433+
434+
final ByteArrayOutputStream targetBytes = new ByteArrayOutputStream();
435+
final CBORGenerator gen = cborGenerator(targetBytes);
436+
final CBORParser cborParser = cborParser(sourceBytes);
437+
cborParser.nextToken();
438+
gen.copyCurrentStructure(cborParser);
439+
gen.close();
440+
cborParser.close();
441+
442+
Assert.assertArrayEquals(
443+
sourceBytes.toByteArray(),
444+
targetBytes.toByteArray());
445+
}
425446
}

0 commit comments

Comments
 (0)