Skip to content

Commit

Permalink
Fix [BUG] @ breaks highlighting in hyperlink Textualize#3327
Browse files Browse the repository at this point in the history
Changes -
1. Added '@' in rich.highlighter:ReprHighlighter url regex pattern.
2. Added a test case in test_highlighter for the url with '@'.
  • Loading branch information
subrat-lima committed Aug 15, 2024
1 parent e1e6d74 commit f591471
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rich/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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$_+!`(),.?/;:&=%#~@]*)",
),
]

Expand Down
1 change: 1 addition & 0 deletions tests/test_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def test_wrong_type():
(" 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 ",
[
Expand Down

0 comments on commit f591471

Please sign in to comment.