From 956bfa5fe558557cd5939bd44f522a6ccc5f8d18 Mon Sep 17 00:00:00 2001 From: Luca Salvarani Date: Sun, 30 Jul 2023 00:13:56 +0000 Subject: [PATCH 1/4] Allow tilde in URL (fixes #3057) --- CHANGELOG.md | 5 +++++ CONTRIBUTORS.md | 1 + rich/highlighter.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d5cc8d7..eb07a4107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Fix tilde character (`~`) not included in link regex when printing to console https://github.com/Textualize/rich/issues/3057 ## [13.5.0] - 2023-07-29 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 43165b0ee..40ad4666f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -51,6 +51,7 @@ The following people have contributed to the development of Rich: - [Clément Robert](https://github.com/neutrinoceros) - [Brian Rutledge](https://github.com/bhrutledge) - [Tushar Sadhwani](https://github.com/tusharsadhwani) +- [Luca Salvarani](https://github.com/LukeSavefrogs) - [Paul Sanders](https://github.com/sanders41) - [Tim Savage](https://github.com/timsavage) - [Anthony Shaw](https://github.com/tonybaloney) diff --git a/rich/highlighter.py b/rich/highlighter.py index c2646794a..27714b25b 100644 --- a/rich/highlighter.py +++ b/rich/highlighter.py @@ -98,7 +98,7 @@ class ReprHighlighter(RegexHighlighter): r"(?P(?\B(/[-\w._+]+)*\/)(?P[-\w._+]*)?", r"(?b?'''.*?(?(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#]*)", + r"(?P(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~]*)", ), ] From a6aebd5ecf860c83e8356f0b9fe3efe7b1a7daab Mon Sep 17 00:00:00 2001 From: Luca Salvarani Date: Sun, 30 Jul 2023 11:32:30 +0000 Subject: [PATCH 2/4] tests(highlighter): Add test for tilde in url --- tests/test_highlighter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py index 804efb369..c865459da 100644 --- a/tests/test_highlighter.py +++ b/tests/test_highlighter.py @@ -133,6 +133,7 @@ def test_wrong_type(): (" https://example.org ", [Span(1, 20, "repr.url")]), (" http://example.org ", [Span(1, 19, "repr.url")]), (" http://example.org/index.html ", [Span(1, 30, "repr.url")]), + (" http://example.org/~folder ", [Span(1, 27, "repr.url")]), ("No place like 127.0.0.1", [Span(14, 23, "repr.ipv4")]), ("''", [Span(0, 2, "repr.str")]), ("'hello'", [Span(0, 7, "repr.str")]), From 2dd2daa4f63c5721b060af2e70d722259b819547 Mon Sep 17 00:00:00 2001 From: Luca Salvarani Date: Sun, 30 Jul 2023 11:35:46 +0000 Subject: [PATCH 3/4] tests(highlighter): Add more tests for `repr.url` --- tests/test_highlighter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py index c865459da..9401a46e3 100644 --- a/tests/test_highlighter.py +++ b/tests/test_highlighter.py @@ -133,6 +133,8 @@ def test_wrong_type(): (" https://example.org ", [Span(1, 20, "repr.url")]), (" 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")]), + (" http://example.org/index.html?param1=value1 ", [Span(31, 37, 'repr.attrib_name'), Span(38, 44, 'repr.attrib_value'), Span(1, 44, "repr.url")]), (" http://example.org/~folder ", [Span(1, 27, "repr.url")]), ("No place like 127.0.0.1", [Span(14, 23, "repr.ipv4")]), ("''", [Span(0, 2, "repr.str")]), From 33fcafe6ec28c541203ada9a85bf73e31786f61d Mon Sep 17 00:00:00 2001 From: Luca Salvarani Date: Mon, 31 Jul 2023 08:26:15 +0000 Subject: [PATCH 4/4] Format `test_highlighter.py` using `black` --- tests/test_highlighter.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py index 9401a46e3..30851cf79 100644 --- a/tests/test_highlighter.py +++ b/tests/test_highlighter.py @@ -134,7 +134,14 @@ 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")]), - (" http://example.org/index.html?param1=value1 ", [Span(31, 37, 'repr.attrib_name'), Span(38, 44, 'repr.attrib_value'), Span(1, 44, "repr.url")]), + ( + " http://example.org/index.html?param1=value1 ", + [ + Span(31, 37, "repr.attrib_name"), + Span(38, 44, "repr.attrib_value"), + Span(1, 44, "repr.url"), + ], + ), (" http://example.org/~folder ", [Span(1, 27, "repr.url")]), ("No place like 127.0.0.1", [Span(14, 23, "repr.ipv4")]), ("''", [Span(0, 2, "repr.str")]),