mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-2298 Data view | Fix | Do not crash when failed to parse incorrect number format (#976)
This commit is contained in:
parent
0ec7441293
commit
e526a8ae2f
3 changed files with 8 additions and 1 deletions
|
@ -4563,6 +4563,7 @@ class EditorViewModel(
|
|||
if (!target.isEmpty) {
|
||||
proceedWithSlashItem(item, target.requireTarget())
|
||||
} else {
|
||||
controlPanelInteractor.onEvent(ControlPanelMachine.Event.Slash.OnStop)
|
||||
Timber.e("Slash Widget Error, target is empty")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ object NumberParser {
|
|||
|
||||
fun parse(value: Any?): String? {
|
||||
val doubleValue = when (value) {
|
||||
is String -> value.toDouble()
|
||||
is String -> value.toDoubleOrNull()
|
||||
is Number -> value.toDouble()
|
||||
else -> null
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.anytypeio.anytype.presentation.relations
|
|||
import com.anytypeio.anytype.presentation.number.NumberParser
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class NumberParserTest {
|
||||
|
||||
|
@ -42,4 +43,9 @@ class NumberParserTest {
|
|||
assertEquals("1.11111111111115", NumberParser.parse("1.11111111111115"))
|
||||
assertEquals("1.11111111111115", NumberParser.parse(1.11111111111115))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `null when parse to double is impossible`() {
|
||||
assertNull(NumberParser.parse("+99 11"))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue