Skip to content

Commit 34b6ee7

Browse files
committed
🐛 handle unterminated group when stashing remainder in key segmentation
1 parent dbb0721 commit 34b6ee7

File tree

1 file changed

+6
-3
lines changed
  • qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/internal

1 file changed

+6
-3
lines changed

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/internal/Decoder.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ internal object Decoder {
397397
if (parent.isNotEmpty()) segments.add(parent)
398398

399399
var open = first
400+
var unterminated = false
400401
var depth = 0
401402
while (open >= 0 && depth < maxDepth) {
402403
var i2 = open + 1
@@ -420,6 +421,7 @@ internal object Decoder {
420421
}
421422

422423
if (close < 0) {
424+
unterminated = true
423425
break // unterminated group; stop collecting
424426
}
425427

@@ -429,13 +431,14 @@ internal object Decoder {
429431
}
430432

431433
if (open >= 0) {
432-
// When depth > 0, strictDepth can apply to the remainder.
433-
if (strictDepth) {
434+
// When depth > 0, strictDepth can apply to a *well-formed* remainder.
435+
// Unterminated remainder is wrapped without throwing.
436+
if (strictDepth && !unterminated) {
434437
throw IndexOutOfBoundsException(
435438
"Input depth exceeded depth option of $maxDepth and strictDepth is true"
436439
)
437440
}
438-
// Stash the remainder as a single segment.
441+
// Stash the remainder—unterminated or overflow—as a single segment.
439442
segments.add("[" + key.substring(open) + "]")
440443
}
441444

0 commit comments

Comments
 (0)