Skip to content

Commit

Permalink
Merge pull request #1079 from wordpress-mobile/fix/markSpanSafeColor
Browse files Browse the repository at this point in the history
Safely parse color string
  • Loading branch information
antonis authored Apr 23, 2024
2 parents 3f16fc1 + bfb0955 commit c2e08fa
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ class MarkSpan : CharacterStyle, IAztecInlineSpan {

val color = CssStyleFormatter.getStyleAttribute(attributes,
CssStyleFormatter.CSS_COLOR_ATTRIBUTE)
textColorValue = if (color.isNotEmpty()) {
Color.parseColor(color)
} else {
null
}
textColorValue = safelyParseColor(color)
}

constructor(attributes: AztecAttributes = AztecAttributes(), colorString: String?) : super() {
this.attributes = attributes
textColorValue = safelyParseColor(colorString)
}

textColorValue = if (colorString != null) {
private fun safelyParseColor(colorString: String?): Int? {
if (colorString == null) {
return null
}
return try {
Color.parseColor(colorString)
} else {
} catch (e: IllegalArgumentException) {
// Unknown color
null
}
}
Expand Down

0 comments on commit c2e08fa

Please sign in to comment.