Skip to content

Commit 28e46ed

Browse files
committed
Merge branch '2.18' into 2.19
2 parents f64c8b2 + 3c7875a commit 28e46ed

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,25 @@ protected void _skipIncomplete() throws IOException
33133313
&& type != CBORConstants.MAJOR_TYPE_BYTES) {
33143314
_throwInternal();
33153315
}
3316+
3317+
// [dataformats-binary#599]: If we are in a stringref namespace, we need to
3318+
// actually read and store the string/bytes value instead of just skipping it,
3319+
// so that later string references can find it.
3320+
// The finish methods will determine if the value should be added to the
3321+
// reference table based on shouldReferenceString().
3322+
if (!_stringRefs.empty()) {
3323+
if (type == CBORConstants.MAJOR_TYPE_TEXT) {
3324+
// Need to actually read the text (which may add to stringRefs)
3325+
_finishTextToken(_typeByte);
3326+
} else {
3327+
// For bytes: decode length then read (which may add to stringRefs)
3328+
int len = _decodeExplicitLength(_typeByte & 0x1F);
3329+
_finishBytes(len);
3330+
}
3331+
return;
3332+
}
3333+
3334+
// Standard skip logic when not in stringref namespace
33163335
final int lowBits = _typeByte & 0x1F;
33173336
if (lowBits <= 23) {
33183337
if (lowBits > 0) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.fasterxml.jackson.dataformat.cbor;
2+
3+
import java.util.Arrays;
4+
5+
import com.fasterxml.jackson.core.JsonToken;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
8+
import org.junit.Test;
9+
10+
public class StringRef599Test extends CBORTestBase
11+
{
12+
private final ObjectMapper VANILLA_MAPPER = cborMapper();
13+
private final ObjectMapper REF_MAPPER = cborMapper(cborFactoryBuilder()
14+
.enable(CBORGenerator.Feature.STRINGREF)
15+
.build());
16+
17+
// [dataformats-binary#599]
18+
@Test
19+
public void testDupsNoStringRef() throws Exception
20+
{
21+
_testStringRef(VANILLA_MAPPER);
22+
}
23+
24+
// [dataformats-binary#599]
25+
@Test
26+
public void testDupsWithStringRef() throws Exception
27+
{
28+
_testStringRef(REF_MAPPER);
29+
}
30+
31+
private void _testStringRef(ObjectMapper mapper) throws Exception
32+
{
33+
byte[] cbor = mapper.writeValueAsBytes(Arrays.asList("foo", "foo"));
34+
try (CBORParser p = cborParser(cbor)) {
35+
assertToken(JsonToken.START_ARRAY, p.nextToken());
36+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
37+
// important! Skip String value
38+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
39+
// equally important; try to check second instance
40+
assertEquals("foo", p.getText());
41+
assertToken(JsonToken.END_ARRAY, p.nextToken());
42+
}
43+
}
44+
}

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ No changes since 2.19.1
6666

6767
2.18.5 (not yet released)
6868

69+
#599: (cbor) Unable to deserialize stringref-enabled CBOR with ignored properties
70+
(reported by Yohei K)
6971
#623: (ion) Upgrade `ion-java` dep to 1.11.11 (from 1.11.10)
7072
(requested by @Shaurya0108)
7173

0 commit comments

Comments
 (0)