Fix: overly escape and offset error for markdown v2 and HTML symbols when nested #2312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, PTB is producing incorrect results when formatting a message into the Markdown v2 format (
Message.(text|caption)_markdown_v2). Specifically, when there is any of the need-to-escape characters_*~`>#+-=|{}.!appear in a nested entities, the last few characters was repeated at the end of the range.For example
<b><hashtag>#boldhashtag</hashtag></b>*#boldhashtag*g*#boldhashtag*<b><i>a{b+c}d</i></b>*_a\{b\+c\}d_\\}d**_a\{b\+c\}d_**
<hashtag />is used here just to represent the hashtag entity, Telegram does not support such a tag.The issue is suspected to be caused by the used of escaped text sequence for nested entities, which is causing a discrepancy in the length of text due to the introduction of
\.This PR fixes the issue by using the original text (
orig_text) as a basis for nested entity parsing. It also includes updated tests to address this issue.