1
0
Fork 0
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:
Konstantin Ivanov 2024-03-05 18:41:23 +01:00 committed by uburoiubu
parent 0ec7441293
commit e526a8ae2f
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6
3 changed files with 8 additions and 1 deletions

View file

@ -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")
}
}

View file

@ -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
}

View file

@ -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"))
}
}