fix: reject nested objects inside list elements in the query format#147
Open
OmarAlJarrah wants to merge 1 commit into
Open
fix: reject nested objects inside list elements in the query format#147OmarAlJarrah wants to merge 1 commit into
OmarAlJarrah wants to merge 1 commit into
Conversation
QueryListEncoder/QueryListDecoder are the delegates used while a list property is being encoded or decoded, but unlike the top-level encoder and decoder they never overrode beginStructure(), so a nested @serializable object (or a nested list) inside a list element fell through to the AbstractEncoder/AbstractDecoder defaults instead of being rejected. A List<Contact>-shaped property silently flattened its fields into repeated values on encode, and could throw an unrelated IndexOutOfBoundsException on decode, rather than raising the documented SerializationException. Give both list delegates the same "structure begun here is rejected" guard the top-level encoder/decoder already carry, so nesting is caught uniformly whether it happens at the top level or inside a list element. Also add coverage for the nullable-vs-absent distinction on a non-collection property: the existing nullable test used a defaulted field, so both the encoder's shouldEncodeElementDefault skip and the decoder's isElementOptional short-circuit meant decodeNotNullMark() and encodeNull() were never actually invoked by any test. A required (no-default) nullable property now exercises both the absent (decodes to null) and present-but-empty ("key=" with no value, decodes to "") cases end to end. Closes #106, #127
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QueryListEncoder/QueryListDecoder(the delegates used while aListproperty is being encoded or decoded) never overrodebeginStructure(), so a nested@Serializableobject — or a nested list — inside a list element fell through to theAbstractEncoder/AbstractDecoderdefaults instead of being rejected. AList<Contact>-shaped property silently flattened its fields into repeated values on encode instead of raising the documentedSerializationException, and could throw an unrelatedIndexOutOfBoundsExceptionon decode. Both delegates now carry the same "structure begun here is rejected" guard the top-level encoder/decoder already have, so nesting is caught uniformly whether it happens at the top level or inside a list element.shouldEncodeElementDefaultskip and the decoder'sisElementOptionalshort-circuit meantdecodeNotNullMark()/encodeNull()were never actually invoked by any test, and the "absent" vs. "present but empty" distinction for a scalar nullable property was unverified end to end. A required (no-default) nullable property now exercises both the absent (decodes tonull) and present-but-empty (key=with no value, decodes to"") cases.Test plan
./gradlew :kuri-serde-kotlinx:jvmTest— confirmed the new nesting-rejection tests fail without the fix and pass with it (TDD)./gradlew :kuri-serde-kotlinx:ktlintCheck./gradlew :kuri-serde-kotlinx:detekt./gradlew :kuri-serde-kotlinx:apiCheck(no public API changes — the touched classes areinternal)./gradlew :kuri-serde-kotlinx:jsNodeTest(commonMain was touched)./gradlew :kuri-serde-kotlinx:macosArm64Test(native target, since commonMain changed)Closes #106
Closes #127