File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
json/commonMain/src/kotlinx/serialization/json/internal
json-tests/commonTest/src/kotlinx/serialization Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,27 @@ class JsonPathTest : JsonTestBase() {
156
156
expectPath(expectedPath) { json.decodeFromString(Sealed .serializer(), malformed) }
157
157
}
158
158
159
+ @Serializable
160
+ data class SimpleNested (val n : SimpleNested ? = null , val t : DataObject ? = null )
161
+
162
+ @Serializable
163
+ data object DataObject
164
+
165
+ @Test
166
+ fun testMalformedDataObjectInDeeplyNestedStructure () {
167
+ var outer = SimpleNested (t = DataObject )
168
+ repeat(20 ) {
169
+ outer = SimpleNested (n = outer)
170
+ }
171
+ val str = Json .encodeToString(SimpleNested .serializer(), outer)
172
+ // throw-away data
173
+ Json .decodeFromString(SimpleNested .serializer(), str)
174
+
175
+ val malformed = str.replace(" {}" , " 42" )
176
+ val expectedPath = " $" + " .n" .repeat(20 ) + " .t\n "
177
+ expectPath(expectedPath) { Json .decodeFromString(SimpleNested .serializer(), malformed) }
178
+ }
179
+
159
180
private inline fun expectPath (path : String , block : () -> Unit ) {
160
181
val message = runCatching { block() }
161
182
.exceptionOrNull()!! .message!!
Original file line number Diff line number Diff line change @@ -134,7 +134,9 @@ internal class JsonPath {
134
134
private fun resize () {
135
135
val newSize = currentDepth * 2
136
136
currentObjectPath = currentObjectPath.copyOf(newSize)
137
- indicies = indicies.copyOf(newSize)
137
+ val newIndices = IntArray (newSize) { - 1 }
138
+ indicies.copyInto(newIndices)
139
+ indicies = newIndices
138
140
}
139
141
140
142
override fun toString (): String = getPath()
You can’t perform that action at this time.
0 commit comments