XEP-0461: fix character counting

Turns out we need to include the fallback/end code point,
unlike python slicing conventions
This commit is contained in:
nicoco 2022-11-28 07:15:26 +01:00
parent 9b89401b36
commit fdca7d82c4
2 changed files with 6 additions and 6 deletions

View file

@ -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):

View file

@ -33,7 +33,7 @@ class TestReply(SlixTest):
self.check(
message,
"""
<message xmlns="jabber:client">
<message xmlns="jabber:client">M
<body>12345\nrealbody</body>
<fallback xmlns='urn:xmpp:feature-fallback:0' for='NS'>
<body start="0" end="6" />
@ -55,7 +55,7 @@ class TestReply(SlixTest):
<message xmlns="jabber:client" type="normal">
<body>> Anna wrote:\n> Hi, how are you?\nGreat</body>
<fallback xmlns="urn:xmpp:feature-fallback:0" for="urn:xmpp:reply:0">
<body start='0' end='33' />
<body start='0' end='32' />
</fallback>
</message>
"""