mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-26 11:23:46 +03:00
Fix overlapping markdown entities being skipped
This commit is contained in:
parent
4f80429215
commit
07ece83aba
|
@ -78,7 +78,10 @@ def parse(message, delimiters=None, url_re=None):
|
||||||
(i + len(url_match.group(1))) // 2,
|
(i + len(url_match.group(1))) // 2,
|
||||||
(Mode.URL, url_match.group(2).decode('utf-16le'))
|
(Mode.URL, url_match.group(2).decode('utf-16le'))
|
||||||
))
|
))
|
||||||
i += len(url_match.group(1))
|
# We matched the delimiter which is now gone, and we'll add
|
||||||
|
# +2 before next iteration which will make us skip a character.
|
||||||
|
# Go back by one utf-16 encoded character (-2) to avoid it.
|
||||||
|
i += len(url_match.group(1)) - 2
|
||||||
|
|
||||||
if not url_match:
|
if not url_match:
|
||||||
for d, m in delimiters.items():
|
for d, m in delimiters.items():
|
||||||
|
@ -90,9 +93,12 @@ def parse(message, delimiters=None, url_re=None):
|
||||||
if current == Mode.NONE:
|
if current == Mode.NONE:
|
||||||
result.append(i // 2)
|
result.append(i // 2)
|
||||||
current = m
|
current = m
|
||||||
|
# No need to i -= 2 here because it's been already
|
||||||
|
# checked that next character won't be a delimiter.
|
||||||
else:
|
else:
|
||||||
result[-1] = (result[-1], i // 2, current)
|
result[-1] = (result[-1], i // 2, current)
|
||||||
current = Mode.NONE
|
current = Mode.NONE
|
||||||
|
i -= 2 # Delimiter matched and gone, go back 1 char
|
||||||
break
|
break
|
||||||
|
|
||||||
if i < len(message):
|
if i < len(message):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user