Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 819f4688 authored by Ricki Hirner's avatar Ricki Hirner Committed by GitHub
Browse files

Fix color parsing for empty strings (see #62) (#63)



* Fix color parsing for empty strings
* Use generic exception, add test

Co-authored-by: default avatarMoritz Jordan <jomority@openotter.com>
parent 73a3c70c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ class Css3ColorTest {
        // ARGB value
        assertEquals(0xffffff00.toInt(), Css3Color.colorFromString("#ffffff00"))

        // empty value
        assertNull(Css3Color.colorFromString(""))

        // invalid value
        assertNull(Css3Color.colorFromString("DoesNotExist"))
    }
+3 −1
Original line number Diff line number Diff line
@@ -176,7 +176,8 @@ enum class Css3Color(val argb: Int) {
            fromString(color)?.argb ?:
                try {
                    Color.parseColor(color)
                } catch(e: IllegalArgumentException) {
                } catch(e: Exception) {
                    Ical4Android.log.warning("Invalid color value: $color")
                    null
                }

@@ -190,6 +191,7 @@ enum class Css3Color(val argb: Int) {
                try {
                    valueOf(name.lowercase())
                } catch (e: IllegalArgumentException) {
                    Ical4Android.log.warning("Invalid color name: $name")
                    null
                }