Skip to content

Commit b3ae539

Browse files
committed
fix: make sure there's space for wide characters
`LineBuffer.putString()` did not account for wide characters when adding text to the buffer.
1 parent de69895 commit b3ae539

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package org.codejive.twinkle.util;
2+
3+
public interface StyledAppendable extends Appendable {}

twinkle-core/src/main/java/org/codejive/twinkle/core/text/LineBuffer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,16 @@ public int putStringAt(int index, @NonNull StyledIterator iter) {
213213
break;
214214
}
215215
if (iter.width() == 0) {
216-
// We shouldn't be getting any of these from a StyledIterator, but just in case...
216+
// Skip any zero-width characters
217217
continue;
218218
}
219+
long style = iter.styleState();
220+
if (iter.width() == 2 && (cnt + 1) >= len) {
221+
// Not enough space for a wide character
222+
setCharAt_(startIndex + cnt, style, REPLACEMENT_CHAR);
223+
break;
224+
}
219225
if (cnt < len) {
220-
long style = iter.styleState();
221226
if (iter.isComplex()) {
222227
setCharAt_(startIndex + cnt, style, iter.sequence());
223228
} else {

0 commit comments

Comments
 (0)