diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt index b6bd7f60e..9d065f32a 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt @@ -26,7 +26,7 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan { } private fun safelyParseColor(colorString: String?): Int? { - if (colorString == null) { + if (colorString.isNullOrBlank()) { return null } return try { diff --git a/aztec/src/test/kotlin/org/wordpress/aztec/MarkSpanTest.kt b/aztec/src/test/kotlin/org/wordpress/aztec/MarkSpanTest.kt new file mode 100644 index 000000000..698e7e87f --- /dev/null +++ b/aztec/src/test/kotlin/org/wordpress/aztec/MarkSpanTest.kt @@ -0,0 +1,39 @@ +package org.wordpress.aztec + +import org.junit.Assert +import org.junit.Test +import org.wordpress.aztec.spans.MarkSpan + +class MarkSpanTest { + /** + * Test used to confirm two crashes related are fixed. + * + * https://github.com/wordpress-mobile/WordPress-Android/issues/20738 + */ + @Test + fun `Calling MarkSpan#safelyParseColor with empty string should not cause a crash`() { + var error = false + try { + MarkSpan(colorString = "") + } catch (e: Exception) { + error = true + } + Assert.assertFalse(error) + } + + /** + * Test used to confirm two crashes related are fixed. + * + * https://github.com/wordpress-mobile/WordPress-Android/issues/20694 + */ + @Test + fun `Calling MarkSpan#safelyParseColor with null string should not cause a crash`() { + var error = false + try { + MarkSpan(colorString = null) + } catch (e: Exception) { + error = true + } + Assert.assertFalse(error) + } +}