Repository: Textualize/rich (python)

Issue:
[BUG] Tilde not included in link regex
The following doesn't highlight pas the `~`
```
>>> from rich import print
>>> print("http://127.0.0.1/~foo")
http://127.0.0.1/~foo
```



Pull request description:
Allow tilde in URL (fixes #3057)
This PR fixes #3057.

## Type of changes

- [X] Bug fix
- [ ] New feature
- [ ] Documentation / docstrings
- [x] Tests
- [ ] Other

## Checklist

- [x] I've run the latest [black](https://github.com/psf/black) with default args on new code.
- [X] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
- [x] I've added tests for new code.
- [X] I accept that @willmcgugan may be pedantic in the code review.

## Description

Please describe your changes here. If this fixes a bug, please link to the issue, if possible.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 61d5cc8d..eb07a410 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 43165b0e..40ad4666 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 c2646794..27714b25 100644
--- a/rich/highlighter.py
+++ b/rich/highlighter.py
@@ -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$_+!`(),.?/;:&=%#~]*)",
         ),
     ]
 


Test patch:
diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py
index 804efb36..30851cf7 100644
--- a/tests/test_highlighter.py
+++ b/tests/test_highlighter.py
@@ -133,6 +133,16 @@ highlight_tests = [
     (" 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")]),
     ("'hello'", [Span(0, 7, "repr.str")]),