fix(telegram): handle parentheses in URLs during MarkdownV2 link conversion
The link regex in format_message used [^)]+ for the URL portion, which stopped at the first ) character. URLs with nested parentheses (e.g. Wikipedia links like Python_(programming_language)) were improperly parsed. Use a better regex, which is the same the Slack adapter uses.
This commit is contained in:
committed by
Teknium
parent
ac4e8cb43a
commit
11369a78f9
@@ -2075,7 +2075,7 @@ class TelegramAdapter(BasePlatformAdapter):
|
||||
url = m.group(2).replace('\\', '\\\\').replace(')', '\\)')
|
||||
return _ph(f'[{display}]({url})')
|
||||
|
||||
text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', _convert_link, text)
|
||||
text = re.sub(r'\[([^\]]+)\]\(([^()]*(?:\([^()]*\)[^()]*)*)\)', _convert_link, text)
|
||||
|
||||
# 4) Convert markdown headers (## Title) → bold *Title*
|
||||
def _convert_header(m):
|
||||
|
||||
Reference in New Issue
Block a user