Skip to content
Snippets Groups Projects
Commit c8f9bbdb authored by Philipp Hörist's avatar Philipp Hörist
Browse files

fix: Styling: Parse text correctly which contains uris and addresses

Use one combined regex for uris and addresses so we get no overlaps

Fixes #10974
parent 9914c246
No related branches found
No related tags found
No related merge requests found
......@@ -43,11 +43,13 @@
BLOCK_NESTED_RX = re.compile(PRE_NESTED_RX + '|' + QUOTE_RX, re.S | re.M)
UNQUOTE_RX = re.compile(r'^> |^>', re.M)
URI_RX = r'((?P<protocol>[\w-]+://?|www[.])[\S()<>]+?(?=[,]?(\s|\Z)+))'
URI_RX = re.compile(URI_RX)
URI_RX = r'(?P<uri>([\w-]+://?|www[.])[\S()<>]+?(?=[,]?(\s|\Z)+))'
ADDRESS_RX = r'(?P<address>\b((xmpp|mailto):)?[\w-]*@(\w*?\.)+[\w]+([\?].*?(?=([\s\),]|$)))?)' # noqa: E501
URI_ADDRESS_RX = URI_RX + '|' + ADDRESS_RX
ADDRESS_RX = r'(\b(?P<protocol>(xmpp|mailto):)?[\w-]*@(\w*?\.)+[\w]+([\?].*?(?=([\s\),]|$)))?)' # noqa: E501
URI_RX = re.compile(URI_RX)
ADDRESS_RX = re.compile(ADDRESS_RX)
URI_ADDRESS_RX = re.compile(URI_ADDRESS_RX)
EMOJI_RX = emoji_data.get_regex()
EMOJI_RX = re.compile(EMOJI_RX)
......@@ -319,12 +321,8 @@ def make(match: Match[str], is_address: bool) -> BaseUri:
offset_bytes,
is_address)
for match in URI_RX.finditer(line):
uri = make(match, False)
uris.append(uri)
for match in ADDRESS_RX.finditer(line):
uri = make(match, True)
for match in URI_ADDRESS_RX.finditer(line):
uri = make(match, bool(match.group('address')))
uris.append(uri)
return uris
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment