mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 09:56:45 -06:00
Fix autofill overwriting user data with empty field values (#5649)
This commit is contained in:
parent
44410efe56
commit
20dea9b5ff
@ -11,29 +11,34 @@ import com.x8bit.bitwarden.data.autofill.model.FilledItem
|
||||
fun AutofillView.buildFilledItemOrNull(
|
||||
value: String,
|
||||
): FilledItem? =
|
||||
when (this.data.autofillType) {
|
||||
View.AUTOFILL_TYPE_DATE -> {
|
||||
value
|
||||
.toLongOrNull()
|
||||
?.let { AutofillValue.forDate(it) }
|
||||
}
|
||||
// Do not try to autofill fields that are empty in the vault
|
||||
if (value.isEmpty()) {
|
||||
null
|
||||
} else {
|
||||
when (this.data.autofillType) {
|
||||
View.AUTOFILL_TYPE_DATE -> {
|
||||
value
|
||||
.toLongOrNull()
|
||||
?.let { AutofillValue.forDate(it) }
|
||||
}
|
||||
|
||||
View.AUTOFILL_TYPE_LIST -> this.buildListAutofillValueOrNull(value = value)
|
||||
View.AUTOFILL_TYPE_TEXT -> AutofillValue.forText(value)
|
||||
View.AUTOFILL_TYPE_TOGGLE -> {
|
||||
value
|
||||
.toBooleanStrictOrNull()
|
||||
?.let { AutofillValue.forToggle(it) }
|
||||
}
|
||||
View.AUTOFILL_TYPE_LIST -> this.buildListAutofillValueOrNull(value = value)
|
||||
View.AUTOFILL_TYPE_TEXT -> AutofillValue.forText(value)
|
||||
View.AUTOFILL_TYPE_TOGGLE -> {
|
||||
value
|
||||
.toBooleanStrictOrNull()
|
||||
?.let { AutofillValue.forToggle(it) }
|
||||
}
|
||||
|
||||
else -> null
|
||||
else -> null
|
||||
}
|
||||
?.let { autofillValue ->
|
||||
FilledItem(
|
||||
autofillId = this.data.autofillId,
|
||||
value = autofillValue,
|
||||
)
|
||||
}
|
||||
}
|
||||
?.let { autofillValue ->
|
||||
FilledItem(
|
||||
autofillId = this.data.autofillId,
|
||||
value = autofillValue,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a list [AutofillValue] out of [value] or return null if not possible.
|
||||
|
||||
@ -329,4 +329,24 @@ class AutofillViewExtensionsTest {
|
||||
// Verify
|
||||
assertNull(actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `buildFilledItemOrNull should return null when value is empty`() {
|
||||
// Setup
|
||||
val value = ""
|
||||
val autofillViewData = autofillViewData.copy(
|
||||
autofillType = View.AUTOFILL_TYPE_TEXT,
|
||||
)
|
||||
val autofillView = AutofillView.Login.Username(
|
||||
data = autofillViewData,
|
||||
)
|
||||
|
||||
// Test
|
||||
val actual = autofillView.buildFilledItemOrNull(
|
||||
value = value,
|
||||
)
|
||||
|
||||
// Verify
|
||||
assertNull(actual)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user