Skip to content

Commit 61dfcc5

Browse files
committed
Ensure spans safety.
1 parent f749d3b commit 61dfcc5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,17 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
450450
*/
451451
fun getTextCopy(): Editable {
452452
val copy = SpannableStringBuilder(text.toString())
453-
454453
val spans: Array<Any> = text.getSpans(0, text.length, Any::class.java)
455454

456455
for (span in spans) {
457456
val spanStart = text.getSpanStart(span)
458457
val spanEnd = text.getSpanEnd(span)
459-
val flags = text.getSpanFlags(span)
460-
copy.setSpan(span, spanStart, spanEnd, flags)
458+
459+
// Only set the span if both start and end positions are valid
460+
if (spanStart >= 0 && spanEnd >= 0) {
461+
val flags = text.getSpanFlags(span)
462+
copy.setSpan(span, spanStart, spanEnd, flags)
463+
}
461464
}
462465
return copy
463466
}

0 commit comments

Comments
 (0)