Skip to content

Commit bf01d44

Browse files
authored
Merge pull request #1080 from wordpress-mobile/andy/issue-20738
[Bug] Fix crash and add unit test to cover the issue.
2 parents c2e08fa + 2a2a1d5 commit bf01d44

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan {
2626
}
2727

2828
private fun safelyParseColor(colorString: String?): Int? {
29-
if (colorString == null) {
29+
if (colorString.isNullOrBlank()) {
3030
return null
3131
}
3232
return try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.wordpress.aztec
2+
3+
import org.junit.Assert
4+
import org.junit.Test
5+
import org.wordpress.aztec.spans.MarkSpan
6+
7+
class MarkSpanTest {
8+
/**
9+
* Test used to confirm two crashes related are fixed.
10+
*
11+
* https://github.com/wordpress-mobile/WordPress-Android/issues/20738
12+
*/
13+
@Test
14+
fun `Calling MarkSpan#safelyParseColor with empty string should not cause a crash`() {
15+
var error = false
16+
try {
17+
MarkSpan(colorString = "")
18+
} catch (e: Exception) {
19+
error = true
20+
}
21+
Assert.assertFalse(error)
22+
}
23+
24+
/**
25+
* Test used to confirm two crashes related are fixed.
26+
*
27+
* https://github.com/wordpress-mobile/WordPress-Android/issues/20694
28+
*/
29+
@Test
30+
fun `Calling MarkSpan#safelyParseColor with null string should not cause a crash`() {
31+
var error = false
32+
try {
33+
MarkSpan(colorString = null)
34+
} catch (e: Exception) {
35+
error = true
36+
}
37+
Assert.assertFalse(error)
38+
}
39+
}

0 commit comments

Comments
 (0)