Use proper unicode codepoint offsets for fallback

Stephen Paul Weber created

Change summary

src/main/java/eu/siacs/conversations/entities/Message.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/entities/Message.java 🔗

@@ -397,7 +397,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
         final Element fallback = new Element("fallback", "urn:xmpp:fallback:0").setAttribute("for", "urn:xmpp:reply:0");
         fallback.addChild("body", "urn:xmpp:fallback:0")
                 .setAttribute("start", "0")
-                .setAttribute("end", "" + m.body.length());
+                .setAttribute("end", "" + m.body.codePointCount(0, m.body.length()));
         m.addPayload(fallback);
         return m;
     }
@@ -516,9 +516,9 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
         spans.sort((x, y) -> y.first.compareTo(x.first));
         try {
             for (Pair<Integer, Integer> span : spans) {
-                body.delete(span.first, span.second);
+                body.delete(body.offsetByCodePoints(0, span.first.intValue()), body.offsetByCodePoints(0, span.second.intValue()));
             }
-        } catch (final StringIndexOutOfBoundsException e) { spans.clear(); }
+        } catch (final IndexOutOfBoundsException e) { spans.clear(); }
 
         if (spans.isEmpty() && getOob() != null) {
             return body.toString().replace(getOob().toString(), "");