Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

## Unreleased

### Behavioral Changes

- Nav3: If a back stack entry's arguments contain a map with two keys that are recorded as the same string (e.g., `1` and `"1"`), Sentry now drops that entry's arguments and records `dropped_by_sentry: duplicate_key`, instead of keeping only one of the values ([#6701](https://github.com/getsentry/sentry-java/pull/6701))

### Dependencies

- Nav3: `sentry-android-navigation3` no longer declares a dependency on `androidx.lifecycle:lifecycle-runtime-compose`. Nav3 apps already depend on it via `navigation3-ui`, so no app changes are necessary ([#6699](https://github.com/getsentry/sentry-java/pull/6699))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ internal class BackStackConverter<T : Any>(
for ((key, childValue) in value) {
val keyString = key.toString()
consumeCharacters(keyString.length)
if (sanitized.containsKey(keyString)) {
throw DropSubtree(
"Nav3 map keys stringify to the same string. Dropping this entry's arguments.",
ArgumentDropReason.DUPLICATE_KEY,
)
}
sanitized[keyString] = sanitizeValue(childValue, depth + 1)
}
return sanitized
Expand Down Expand Up @@ -427,6 +433,7 @@ internal enum class ArgumentDropReason(
) {

CHARACTER_LIMIT("max_character_limit_exceeded", exhaustsUpdateBudget = true),
DUPLICATE_KEY("duplicate_key"),
INVALID_STRUCTURE("invalid_structure"),
MAPPING_FAILED("mapping_failed"),
MAX_COUNT("max_argument_count_exceeded", exhaustsUpdateBudget = true),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.sentry.compose.navigation3.internal.backstack

import com.google.common.truth.Truth.assertThat
import io.sentry.NoOpLogger
import org.junit.Test

class ArgumentDuplicateKeysTest {
@Test
fun `stringified key collisions drop only that entry`() {
val sanitizer =
BackStackConverter.ArgumentSanitizer(
NoOpLogger.getInstance(),
BackStackConverter.WarningState(),
)
val result =
sanitizer.sanitizeEntry(
mapOf("nested" to linkedMapOf<Any, Any>(1 to "first", "1" to "second")),
)
assertThat(result.values).isEmpty()
assertThat(result.dropReason).isEqualTo(ArgumentDropReason.DUPLICATE_KEY)
val next = sanitizer.sanitizeEntry(mapOf("id" to 123))
assertThat(next.dropReason).isNull()
assertThat(next.values).containsExactly("id", 123)
}
}
Loading