Skip to content

Commit

Permalink
Merge pull request #1080 from wordpress-mobile/andy/issue-20738
Browse files Browse the repository at this point in the history
[Bug] Fix crash and add unit test to cover the issue.
  • Loading branch information
notandyvee authored May 6, 2024
2 parents c2e08fa + 2a2a1d5 commit bf01d44
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan {
}

private fun safelyParseColor(colorString: String?): Int? {
if (colorString == null) {
if (colorString.isNullOrBlank()) {
return null
}
return try {
Expand Down
39 changes: 39 additions & 0 deletions aztec/src/test/kotlin/org/wordpress/aztec/MarkSpanTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit bf01d44

Please sign in to comment.