mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 03:08:50 +03:00
BIT-2442: check type before extracting autofill text (#3394)
This commit is contained in:
parent
b181d0d026
commit
bb6a7af423
2 changed files with 25 additions and 4 deletions
|
@ -26,7 +26,12 @@ fun AutofillValue.extractMonthValue(
|
|||
/**
|
||||
* Extract a text value from this [AutofillValue].
|
||||
*/
|
||||
fun AutofillValue.extractTextValue(): String? = this
|
||||
.textValue
|
||||
.takeIf { it.isNotBlank() }
|
||||
?.toString()
|
||||
fun AutofillValue.extractTextValue(): String? =
|
||||
if (this.isText) {
|
||||
this
|
||||
.textValue
|
||||
.takeIf { it.isNotBlank() }
|
||||
?.toString()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ class AutofillValueExtensionsTest {
|
|||
fun `extractTextValue should return textValue when not blank`() {
|
||||
// Setup
|
||||
val autofillValue: AutofillValue = mockk {
|
||||
every { isText } returns true
|
||||
every { textValue } returns TEXT_VALUE
|
||||
}
|
||||
|
||||
|
@ -93,6 +94,7 @@ class AutofillValueExtensionsTest {
|
|||
fun `extractTextValue should return null when not blank`() {
|
||||
// Setup
|
||||
val autofillValue: AutofillValue = mockk {
|
||||
every { isText } returns true
|
||||
every { textValue } returns " "
|
||||
}
|
||||
|
||||
|
@ -102,6 +104,20 @@ class AutofillValueExtensionsTest {
|
|||
// Verify
|
||||
assertNull(actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `extractTextValue should return null when not text`() {
|
||||
// Setup
|
||||
val autofillValue: AutofillValue = mockk {
|
||||
every { isText } returns false
|
||||
}
|
||||
|
||||
// Test
|
||||
val actual = autofillValue.extractTextValue()
|
||||
|
||||
// Verify
|
||||
assertNull(actual)
|
||||
}
|
||||
}
|
||||
|
||||
private const val LIST_VALUE: Int = 5
|
||||
|
|
Loading…
Add table
Reference in a new issue