From fdca7d82c427b2da77f852b9e2f882decedd257a Mon Sep 17 00:00:00 2001 From: nicoco Date: Mon, 28 Nov 2022 07:15:26 +0100 Subject: [PATCH] XEP-0461: fix character counting Turns out we need to include the fallback/end code point, unlike python slicing conventions --- slixmpp/plugins/xep_0461/stanza.py | 8 ++++---- tests/test_stanza_xep_0461.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/slixmpp/plugins/xep_0461/stanza.py b/slixmpp/plugins/xep_0461/stanza.py index 09a25f97..f52d0964 100644 --- a/slixmpp/plugins/xep_0461/stanza.py +++ b/slixmpp/plugins/xep_0461/stanza.py @@ -23,8 +23,8 @@ class FeatureFallBack(ElementBase): start = self["fallback_body"]["start"] end = self["fallback_body"]["end"] body = self.parent()["body"] - if start < end < len(body): - return body[start:end] + if start <= end: + return body[start:end+1] else: return "" @@ -33,7 +33,7 @@ class FeatureFallBack(ElementBase): start = self["fallback_body"]["start"] end = self["fallback_body"]["end"] body = self.parent()["body"] - if start < end < len(body): + if start <= end < len(body): return body[:start] + body[end:] else: return body @@ -44,7 +44,7 @@ class FeatureFallBack(ElementBase): msg["body"] = quoted + msg["body"] msg["feature_fallback"]["for"] = NS msg["feature_fallback"]["fallback_body"]["start"] = 0 - msg["feature_fallback"]["fallback_body"]["end"] = len(quoted) + msg["feature_fallback"]["fallback_body"]["end"] = len(quoted) - 1 class FallBackBody(ElementBase): diff --git a/tests/test_stanza_xep_0461.py b/tests/test_stanza_xep_0461.py index 76f07c80..e43b8138 100644 --- a/tests/test_stanza_xep_0461.py +++ b/tests/test_stanza_xep_0461.py @@ -33,7 +33,7 @@ class TestReply(SlixTest): self.check( message, """ - + M 12345\nrealbody @@ -55,7 +55,7 @@ class TestReply(SlixTest): > Anna wrote:\n> Hi, how are you?\nGreat - + """