Skip to content

Commit f591471

Browse files
author
subrat-lima
committed
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 '@'.
1 parent e1e6d74 commit f591471

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

rich/highlighter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ReprHighlighter(RegexHighlighter):
9898
r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[-+]?\d+?)?\b|0x[0-9a-fA-F]*)",
9999
r"(?P<path>\B(/[-\w._+]+)*\/)(?P<filename>[-\w._+]*)?",
100100
r"(?<![\\\w])(?P<str>b?'''.*?(?<!\\)'''|b?'.*?(?<!\\)'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
101-
r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~]*)",
101+
r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~@]*)",
102102
),
103103
]
104104

tests/test_highlighter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def test_wrong_type():
134134
(" http://example.org ", [Span(1, 19, "repr.url")]),
135135
(" http://example.org/index.html ", [Span(1, 30, "repr.url")]),
136136
(" http://example.org/index.html#anchor ", [Span(1, 37, "repr.url")]),
137+
("https://www.youtube.com/@LinusTechTips", [Span(0, 38, "repr.url")]),
137138
(
138139
" http://example.org/index.html?param1=value1 ",
139140
[

0 commit comments

Comments
 (0)