Skip to content

Commit c57d5c2

Browse files
committed
support @id/foo case
1 parent ef6b1e1 commit c57d5c2

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

sdk/@launchdarkly/observability-android/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ val sessionReplay = SessionReplay(
247247
),
248248
maskXMLViewIds = listOf(
249249
// Masks by resource entry name (from resources.getResourceEntryName(view.id)).
250-
// Accepts either "@+id/foo" or "foo".
250+
// Accepts "@+id/foo", "@id/foo", or "foo".
251251
"@+id/password",
252252
"credit_card_number",
253253
),

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/replay/PrivacyProfile.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import com.launchdarkly.observability.replay.masking.MaskTarget
1818
* @param maskImageViews Set to true to mask [ImageView] targets by exact class match.
1919
* @param maskViews Additional Views to mask by exact class match (see [viewsMatcher]).
2020
* @param maskXMLViewIds Additional Views to mask by resource entry name (see [xmlViewIdsMatcher]).
21-
* Accepts either `"@+id/foo"` or `"foo"`.
21+
* Accepts `"@+id/foo"`, `"@id/foo"`, or `"foo"`.
2222
* @param maskAdditionalMatchers Additional custom matchers to apply.
2323
**/
2424
data class PrivacyProfile(
@@ -37,8 +37,11 @@ data class PrivacyProfile(
3737
}
3838

3939
private val maskXMLViewIdSet = maskXMLViewIds.map {
40-
if (it.startsWith("@+id/")) return@map it.substring(5)
41-
return@map it
40+
when {
41+
it.startsWith("@+id/") -> it.substring(5)
42+
it.startsWith("@id/") -> it.substring(4)
43+
else -> it
44+
}
4245
}.toSet()
4346

4447
/**

sdk/@launchdarkly/observability-android/lib/src/test/kotlin/com/launchdarkly/observability/replay/PrivacyProfileTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,18 @@ class PrivacyProfileTest {
3939
}
4040

4141
@Test
42-
fun `maskXMLViewIds normalizes @+id prefix and adds xmlViewIdsMatcher to matchers list`() {
43-
val profile = PrivacyProfile(maskXMLViewIds = listOf("@+id/foo", "bar"))
42+
fun `maskXMLViewIds normalizes @+id and @id prefixes and adds xmlViewIdsMatcher to matchers list`() {
43+
val profile = PrivacyProfile(maskXMLViewIds = listOf("@+id/foo", "@id/baz", "bar"))
4444

4545
val matchers = profile.asMatchersList()
4646
assertTrue(matchers.contains(profile.xmlViewIdsMatcher))
4747

4848
val idSet = profile.getPrivateSet("maskXMLViewIdSet")
4949
assertTrue(idSet.contains("foo"))
50+
assertTrue(idSet.contains("baz"))
5051
assertTrue(idSet.contains("bar"))
5152
assertFalse(idSet.contains("@+id/foo"))
53+
assertFalse(idSet.contains("@id/baz"))
5254
}
5355

5456
@Test

0 commit comments

Comments
 (0)