Fix [BUG] @ breaks highlighting in hyperlink #3327

Changes -
1. Added '@' in rich.highlighter:ReprHighlighter url regex pattern.
2. Added a test case in test_highlighter for the url with '@'.
This commit is contained in:
subrat-lima 2024-08-15 21:21:18 +05:30
parent e1e6d745f6
commit f591471cf0
2 changed files with 2 additions and 1 deletions

View File

@ -98,7 +98,7 @@ class ReprHighlighter(RegexHighlighter):
r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[-+]?\d+?)?\b|0x[0-9a-fA-F]*)",
r"(?P<path>\B(/[-\w._+]+)*\/)(?P<filename>[-\w._+]*)?",
r"(?<![\\\w])(?P<str>b?'''.*?(?<!\\)'''|b?'.*?(?<!\\)'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~]*)",
r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~@]*)",
),
]

View File

@ -134,6 +134,7 @@ highlight_tests = [
(" http://example.org ", [Span(1, 19, "repr.url")]),
(" http://example.org/index.html ", [Span(1, 30, "repr.url")]),
(" http://example.org/index.html#anchor ", [Span(1, 37, "repr.url")]),
("https://www.youtube.com/@LinusTechTips", [Span(0, 38, "repr.url")]),
(
" http://example.org/index.html?param1=value1 ",
[