forked from Kotlin/kotlinx.serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow repeated keys in CBOR (WIP, need to add config switches)
Fixes Kotlin#2662 by adding a `visitKey` method to `CompositeDecoder`; map and set serializers should call this so that decoders have an opportunity to throw an error when a duplicate key is detected. Also fixes a typo in an unrelated method docstring.
- Loading branch information
Showing
5 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
formats/cbor/commonTest/src/kotlinx/serialization/cbor/CborStrictModeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kotlinx.serialization.cbor | ||
|
||
import kotlinx.serialization.assertFailsWithMessage | ||
import kotlinx.serialization.decodeFromByteArray | ||
import kotlinx.serialization.HexConverter | ||
import kotlinx.serialization.DuplicateMapKeyException | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CborStrictModeTest { | ||
|
||
/** Duplicate keys are rejected. */ | ||
@Test | ||
fun testDuplicateKeys() { | ||
val duplicateKeys = HexConverter.parseHexBinary("A2617805617806") | ||
assertFailsWithMessage<DuplicateMapKeyException>("Duplicate keys not allowed in maps") { | ||
Cbor.decodeFromByteArray<Map<String, Long>>(duplicateKeys) | ||
} | ||
} | ||
} |