Skip to content

Commit 16143c1

Browse files
Fix case sensitivity issues in attribute key
1 parent 6fb67c6 commit 16143c1

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

src/main/kotlin/com/mparticle/kits/RoktKit.kt

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
200200
finalAttributes[MPID] = mpid
201201
} ?: Logger.warning("RoktKit: No user ID available for placement")
202202

203-
//addIdentityAttributes(finalAttributes, filterUser)
203+
addIdentityAttributes(finalAttributes, filterUser)
204204

205205

206206
val SANDBOX_MODE_ROKT: String = "sandbox"
@@ -323,27 +323,47 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
323323
private fun verifyHashedEmail(attributes: MutableMap<String, String>?) {
324324
if (attributes == null) return
325325

326-
val emailKey = "Email"
327-
val otherKey = "Other"
326+
val emailKey = MParticle.IdentityType.Email.name.lowercase()
327+
val otherKey = MParticle.IdentityType.Other.name.lowercase()
328328
val emailShaKey = "emailsha256"
329329

330-
val emailSha = attributes[emailShaKey]
331-
val otherValue = attributes[otherKey]
330+
val emailSha = attributes.entries.find { it.key.equals(emailShaKey, ignoreCase = true) }?.value
331+
val otherValue = attributes.entries.find { it.key.equals(otherKey, ignoreCase = true) }?.value
332332

333333
when {
334334
!emailSha.isNullOrEmpty() -> {
335-
attributes.remove(emailKey)
336-
attributes.remove(otherKey)
335+
// If emailsha256 is already present, remove entries with email and other keys
336+
val iterator = attributes.entries.iterator()
337+
while (iterator.hasNext()) {
338+
val entry = iterator.next()
339+
if (entry.key.equals(emailKey, ignoreCase = true) ||
340+
entry.key.equals(otherKey, ignoreCase = true)) {
341+
iterator.remove()
342+
}
343+
}
337344
}
338345

339346
!otherValue.isNullOrEmpty() -> {
340-
attributes.remove(emailKey)
347+
// If "other" has a value, treat it as hashed email
348+
val iterator = attributes.entries.iterator()
349+
while (iterator.hasNext()) {
350+
val entry = iterator.next()
351+
if (entry.key.equals(emailKey, ignoreCase = true)) {
352+
iterator.remove()
353+
}
354+
}
341355
attributes[emailShaKey] = otherValue
342-
attributes.remove(otherKey)
356+
val iterator2 = attributes.entries.iterator()
357+
while (iterator2.hasNext()) {
358+
val entry = iterator2.next()
359+
if (entry.key.equals(otherKey, ignoreCase = true)) {
360+
iterator2.remove()
361+
}
362+
}
343363
}
344-
345-
// else do nothing
364+
// else: do nothing
346365
}
366+
Logger.debug("Mansi "+attributes.size)
347367
}
348368

349369
private fun getStringForIdentity(identityType: IdentityType): String {

0 commit comments

Comments
 (0)