diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java index 6c5cc0587..d2d9d8d7e 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java @@ -3414,6 +3414,25 @@ protected void _skipIncomplete() throws IOException && type != CBORConstants.MAJOR_TYPE_BYTES) { _throwInternal(); } + + // [dataformats-binary#599]: If we are in a stringref namespace, we need to + // actually read and store the string/bytes value instead of just skipping it, + // so that later string references can find it. + // The finish methods will determine if the value should be added to the + // reference table based on shouldReferenceString(). + if (!_stringRefs.empty()) { + if (type == CBORConstants.MAJOR_TYPE_TEXT) { + // Need to actually read the text (which may add to stringRefs) + _finishTextToken(_typeByte); + } else { + // For bytes: decode length then read (which may add to stringRefs) + int len = _decodeExplicitLength(_typeByte & 0x1F); + _finishBytes(len); + } + return; + } + + // Standard skip logic when not in stringref namespace final int lowBits = _typeByte & 0x1F; if (lowBits <= 23) { if (lowBits > 0) { diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/tofix/StringRef599Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringRef599Test.java similarity index 86% rename from cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/tofix/StringRef599Test.java rename to cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringRef599Test.java index 2183e2305..758991608 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/tofix/StringRef599Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringRef599Test.java @@ -1,13 +1,10 @@ -package com.fasterxml.jackson.dataformat.cbor.tofix; +package com.fasterxml.jackson.dataformat.cbor; import java.util.Arrays; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.cbor.*; -import com.fasterxml.jackson.dataformat.cbor.testutil.failure.JacksonTestFailureExpected; - import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; @@ -27,7 +24,6 @@ public void testDupsNoStringRef() throws Exception } // [dataformats-binary#599] - @JacksonTestFailureExpected @Test public void testDupsWithStringRef() throws Exception { diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 182befa7e..16598b7b5 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -422,3 +422,7 @@ Vincent Eigenberger (@beseder1) * Contributed fix for #601: Jackson subtype Avro schema unions are non-deterministic and therefore incompatible with each other (2.20.1) + +Yohei Kishimoto (@morokosi) + * Reported #599: (cbor) Unable to deserialize stringref-enabled CBOR with ignored properties + (2.21.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index a433504f5..9ad755f27 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,6 +16,8 @@ Active maintainers: 2.21.0 (not yet released) +#599: (cbor) Unable to deserialize stringref-enabled CBOR with ignored properties + (reported by Yohei K) #623: (ion) Upgrade `ion-java` dep to 1.11.11 (from 1.11.10) (requested by @Shaurya0108)