Skip to content

Commit c2e08fa

Browse files
authored
Merge pull request #1079 from wordpress-mobile/fix/markSpanSafeColor
Safely parse color string
2 parents 3f16fc1 + bfb0955 commit c2e08fa

File tree

1 file changed

+10
-7
lines changed
  • aztec/src/main/kotlin/org/wordpress/aztec/spans

1 file changed

+10
-7
lines changed

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan {
1717

1818
val color = CssStyleFormatter.getStyleAttribute(attributes,
1919
CssStyleFormatter.CSS_COLOR_ATTRIBUTE)
20-
textColorValue = if (color.isNotEmpty()) {
21-
Color.parseColor(color)
22-
} else {
23-
null
24-
}
20+
textColorValue = safelyParseColor(color)
2521
}
2622

2723
constructor(attributes: AztecAttributes = AztecAttributes(), colorString: String?) : super() {
2824
this.attributes = attributes
25+
textColorValue = safelyParseColor(colorString)
26+
}
2927

30-
textColorValue = if (colorString != null) {
28+
private fun safelyParseColor(colorString: String?): Int? {
29+
if (colorString == null) {
30+
return null
31+
}
32+
return try {
3133
Color.parseColor(colorString)
32-
} else {
34+
} catch (e: IllegalArgumentException) {
35+
// Unknown color
3336
null
3437
}
3538
}

0 commit comments

Comments
 (0)