prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [BUG] '#' sign is treated as the end of a URL
  **Describe the bug**
  The `#` a valid element of the URL, but Rich seems to ignore it and treats it as the end of it. 
  Consider this URL: https://github.com/willmcgugan/rich#rich-print-function
  
  **To Reproduce**
  ```python
  from rich.console import Console
  
  console = Console()
  
  console.log("https://github.com/willmcgugan/rich#rich-print-function")
  ```
  
  Output:  
  ![image](https://user-images.githubusercontent.com/18279161/92566941-44f59380-f27d-11ea-908d-64d01e224087.png)
  
  
  **Platform**
  I'm using Rich on Windows and Linux, with the currently newest version `6.1.1`.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `rich/highlighter.py`
  Content:
  ```
  1 from abc import ABC, abstractmethod
  2 from typing import List, Union
  3 
  4 from .text import Text
  5 
  6 
  7 class Highlighter(ABC):
  8     """Abstract base class for highlighters."""
  9 
  10     def __call__(self, text: Union[str, Text]) -> Text:
  11         """Highlight a str or Text instance.
  12 
  13         Args:
  14             text (Union[str, ~Text]): Text to highlight.
  15 
  16         Raises:
  17             TypeError: If not called with text or str.
  18 
  19         Returns:
  20             Text: A test instance with highlighting applied.
  21         """
  22         if isinstance(text, str):
  23             highlight_text = Text(text)
  24         elif isinstance(text, Text):
  25             highlight_text = text.copy()
  26         else:
  27             raise TypeError(f"str or Text instance required, not {text!r}")
  28         self.highlight(highlight_text)
  29         return highlight_text
  30 
  31     @abstractmethod
  32     def highlight(self, text: Text) -> None:
  33         """Apply highlighting in place to text.
  34 
  35         Args:
  36             text (~Text): A text object highlight.
  37         """
  38 
  39 
  40 class NullHighlighter(Highlighter):
  41     """A highlighter object that doesn't highlight.
  42 
  43     May be used to disable highlighting entirely.
  44 
  45     """
  46 
  47     def highlight(self, text: Text) -> None:
  48         """Nothing to do"""
  49 
  50 
  51 class RegexHighlighter(Highlighter):
  52     """Applies highlighting from a list of regular expressions."""
  53 
  54     highlights: List[str] = []
  55     base_style: str = ""
  56 
  57     def highlight(self, text: Text) -> None:
  58         """Highlight :class:`rich.text.Text` using regular expressions.
  59 
  60         Args:
  61             text (~Text): Text to highlighted.
  62 
  63         """
  64         highlight_regex = text.highlight_regex
  65         for re_highlight in self.highlights:
  66             highlight_regex(re_highlight, style_prefix=self.base_style)
  67 
  68 
  69 class ReprHighlighter(RegexHighlighter):
  70     """Highlights the text typically produced from ``__repr__`` methods."""
  71 
  72     base_style = "repr."
  73     highlights = [
  74         r"(?P<brace>[\{\[\(\)\]\}])",
  75         r"(?P<tag_start>\<)(?P<tag_name>[\w\-\.\:]*)(?P<tag_contents>.*?)(?P<tag_end>\>)",
  76         r"(?P<attrib_name>\w+?)=(?P<attrib_value>\"?[\w_]+\"?)",
  77         r"(?P<bool_true>True)|(?P<bool_false>False)|(?P<none>None)",
  78         r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[\-\+]?\d+?)?\b)",
  79         r"(?P<number>0x[0-9a-f]*)",
  80         r"(?P<path>\B(\/[\w\.\-\_\+]+)*\/)(?P<filename>[\w\.\-\_\+]*)?",
  81         r"(?<!\\)(?P<str>b?\'\'\'.*?(?<!\\)\'\'\'|b?\'.*?(?<!\\)\'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
  82         r"(?P<url>https?:\/\/[0-9a-zA-Z\$\-\_\+\!`\(\)\,\.\?\/\;\:\&\=\%]*)",
  83         r"(?P<uuid>[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12})",
  84     ]
  85 
  86 
  87 if __name__ == "__main__":  # pragma: no cover
  88     from .console import Console
  89 
  90     console = Console()
  91     console.print("[bold green]hello world![/bold green]")
  92     console.print("'[bold green]hello world![/bold green]'")
  93 
  94     console.print(" /foo")
  95     console.print("/foo/")
  96     console.print("/foo/bar")
  97     console.print("foo/bar/baz")
  98 
  99     console.print("/foo/bar/baz?foo=bar+egg&egg=baz")
  100     console.print("/foo/bar/baz/")
  101     console.print("/foo/bar/baz/egg")
  102     console.print("/foo/bar/baz/egg.py")
  103     console.print("/foo/bar/baz/egg.py word")
  104     console.print(" /foo/bar/baz/egg.py word")
  105     console.print("foo /foo/bar/baz/egg.py word")
  106     console.print("foo /foo/bar/ba._++z/egg+.py word")
  107     console.print("https://example.org?foo=bar")
  108 
  109     console.print(1234567.34)
  110     console.print(1 / 2)
  111     console.print(-1 / 123123123123)
  112
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/rich/highlighter.py b/rich/highlighter.py
  --- a/rich/highlighter.py
  +++ b/rich/highlighter.py
  @@ -79,7 +79,7 @@
           r"(?P<number>0x[0-9a-f]*)",
           r"(?P<path>\B(\/[\w\.\-\_\+]+)*\/)(?P<filename>[\w\.\-\_\+]*)?",
           r"(?<!\\)(?P<str>b?\'\'\'.*?(?<!\\)\'\'\'|b?\'.*?(?<!\\)\'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
  -        r"(?P<url>https?:\/\/[0-9a-zA-Z\$\-\_\+\!`\(\)\,\.\?\/\;\:\&\=\%]*)",
  +        r"(?P<url>https?:\/\/[0-9a-zA-Z\$\-\_\+\!`\(\)\,\.\?\/\;\:\&\=\%\#]*)",
           r"(?P<uuid>[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12})",
       ]
   
  @@ -104,7 +104,7 @@
       console.print(" /foo/bar/baz/egg.py word")
       console.print("foo /foo/bar/baz/egg.py word")
       console.print("foo /foo/bar/ba._++z/egg+.py word")
  -    console.print("https://example.org?foo=bar")
  +    console.print("https://example.org?foo=bar#header")
   
       console.print(1234567.34)
       console.print(1 / 2)
  
verification_info: {"golden_diff": "diff --git a/rich/highlighter.py b/rich/highlighter.py\n--- a/rich/highlighter.py\n+++ b/rich/highlighter.py\n@@ -79,7 +79,7 @@\n         r\"(?P<number>0x[0-9a-f]*)\",\n         r\"(?P<path>\\B(\\/[\\w\\.\\-\\_\\+]+)*\\/)(?P<filename>[\\w\\.\\-\\_\\+]*)?\",\n         r\"(?<!\\\\)(?P<str>b?\\'\\'\\'.*?(?<!\\\\)\\'\\'\\'|b?\\'.*?(?<!\\\\)\\'|b?\\\"\\\"\\\".*?(?<!\\\\)\\\"\\\"\\\"|b?\\\".*?(?<!\\\\)\\\")\",\n-        r\"(?P<url>https?:\\/\\/[0-9a-zA-Z\\$\\-\\_\\+\\!`\\(\\)\\,\\.\\?\\/\\;\\:\\&\\=\\%]*)\",\n+        r\"(?P<url>https?:\\/\\/[0-9a-zA-Z\\$\\-\\_\\+\\!`\\(\\)\\,\\.\\?\\/\\;\\:\\&\\=\\%\\#]*)\",\n         r\"(?P<uuid>[a-fA-F0-9]{8}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{12})\",\n     ]\n \n@@ -104,7 +104,7 @@\n     console.print(\" /foo/bar/baz/egg.py word\")\n     console.print(\"foo /foo/bar/baz/egg.py word\")\n     console.print(\"foo /foo/bar/ba._++z/egg+.py word\")\n-    console.print(\"https://example.org?foo=bar\")\n+    console.print(\"https://example.org?foo=bar#header\")\n \n     console.print(1234567.34)\n     console.print(1 / 2)\n", "issue": "[BUG] '#' sign is treated as the end of a URL\n**Describe the bug**\r\nThe `#` a valid element of the URL, but Rich seems to ignore it and treats it as the end of it. \r\nConsider this URL: https://github.com/willmcgugan/rich#rich-print-function\r\n\r\n**To Reproduce**\r\n```python\r\nfrom rich.console import Console\r\n\r\nconsole = Console()\r\n\r\nconsole.log(\"https://github.com/willmcgugan/rich#rich-print-function\")\r\n```\r\n\r\nOutput:  \r\n![image](https://user-images.githubusercontent.com/18279161/92566941-44f59380-f27d-11ea-908d-64d01e224087.png)\r\n\r\n\r\n**Platform**\r\nI'm using Rich on Windows and Linux, with the currently newest version `6.1.1`.\r\n\n", "before_files": [{"content": "from abc import ABC, abstractmethod\nfrom typing import List, Union\n\nfrom .text import Text\n\n\nclass Highlighter(ABC):\n    \"\"\"Abstract base class for highlighters.\"\"\"\n\n    def __call__(self, text: Union[str, Text]) -> Text:\n        \"\"\"Highlight a str or Text instance.\n\n        Args:\n            text (Union[str, ~Text]): Text to highlight.\n\n        Raises:\n            TypeError: If not called with text or str.\n\n        Returns:\n            Text: A test instance with highlighting applied.\n        \"\"\"\n        if isinstance(text, str):\n            highlight_text = Text(text)\n        elif isinstance(text, Text):\n            highlight_text = text.copy()\n        else:\n            raise TypeError(f\"str or Text instance required, not {text!r}\")\n        self.highlight(highlight_text)\n        return highlight_text\n\n    @abstractmethod\n    def highlight(self, text: Text) -> None:\n        \"\"\"Apply highlighting in place to text.\n\n        Args:\n            text (~Text): A text object highlight.\n        \"\"\"\n\n\nclass NullHighlighter(Highlighter):\n    \"\"\"A highlighter object that doesn't highlight.\n\n    May be used to disable highlighting entirely.\n\n    \"\"\"\n\n    def highlight(self, text: Text) -> None:\n        \"\"\"Nothing to do\"\"\"\n\n\nclass RegexHighlighter(Highlighter):\n    \"\"\"Applies highlighting from a list of regular expressions.\"\"\"\n\n    highlights: List[str] = []\n    base_style: str = \"\"\n\n    def highlight(self, text: Text) -> None:\n        \"\"\"Highlight :class:`rich.text.Text` using regular expressions.\n\n        Args:\n            text (~Text): Text to highlighted.\n\n        \"\"\"\n        highlight_regex = text.highlight_regex\n        for re_highlight in self.highlights:\n            highlight_regex(re_highlight, style_prefix=self.base_style)\n\n\nclass ReprHighlighter(RegexHighlighter):\n    \"\"\"Highlights the text typically produced from ``__repr__`` methods.\"\"\"\n\n    base_style = \"repr.\"\n    highlights = [\n        r\"(?P<brace>[\\{\\[\\(\\)\\]\\}])\",\n        r\"(?P<tag_start>\\<)(?P<tag_name>[\\w\\-\\.\\:]*)(?P<tag_contents>.*?)(?P<tag_end>\\>)\",\n        r\"(?P<attrib_name>\\w+?)=(?P<attrib_value>\\\"?[\\w_]+\\\"?)\",\n        r\"(?P<bool_true>True)|(?P<bool_false>False)|(?P<none>None)\",\n        r\"(?P<number>(?<!\\w)\\-?[0-9]+\\.?[0-9]*(e[\\-\\+]?\\d+?)?\\b)\",\n        r\"(?P<number>0x[0-9a-f]*)\",\n        r\"(?P<path>\\B(\\/[\\w\\.\\-\\_\\+]+)*\\/)(?P<filename>[\\w\\.\\-\\_\\+]*)?\",\n        r\"(?<!\\\\)(?P<str>b?\\'\\'\\'.*?(?<!\\\\)\\'\\'\\'|b?\\'.*?(?<!\\\\)\\'|b?\\\"\\\"\\\".*?(?<!\\\\)\\\"\\\"\\\"|b?\\\".*?(?<!\\\\)\\\")\",\n        r\"(?P<url>https?:\\/\\/[0-9a-zA-Z\\$\\-\\_\\+\\!`\\(\\)\\,\\.\\?\\/\\;\\:\\&\\=\\%]*)\",\n        r\"(?P<uuid>[a-fA-F0-9]{8}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{12})\",\n    ]\n\n\nif __name__ == \"__main__\":  # pragma: no cover\n    from .console import Console\n\n    console = Console()\n    console.print(\"[bold green]hello world![/bold green]\")\n    console.print(\"'[bold green]hello world![/bold green]'\")\n\n    console.print(\" /foo\")\n    console.print(\"/foo/\")\n    console.print(\"/foo/bar\")\n    console.print(\"foo/bar/baz\")\n\n    console.print(\"/foo/bar/baz?foo=bar+egg&egg=baz\")\n    console.print(\"/foo/bar/baz/\")\n    console.print(\"/foo/bar/baz/egg\")\n    console.print(\"/foo/bar/baz/egg.py\")\n    console.print(\"/foo/bar/baz/egg.py word\")\n    console.print(\" /foo/bar/baz/egg.py word\")\n    console.print(\"foo /foo/bar/baz/egg.py word\")\n    console.print(\"foo /foo/bar/ba._++z/egg+.py word\")\n    console.print(\"https://example.org?foo=bar\")\n\n    console.print(1234567.34)\n    console.print(1 / 2)\n    console.print(-1 / 123123123123)\n", "path": "rich/highlighter.py"}], "after_files": [{"content": "from abc import ABC, abstractmethod\nfrom typing import List, Union\n\nfrom .text import Text\n\n\nclass Highlighter(ABC):\n    \"\"\"Abstract base class for highlighters.\"\"\"\n\n    def __call__(self, text: Union[str, Text]) -> Text:\n        \"\"\"Highlight a str or Text instance.\n\n        Args:\n            text (Union[str, ~Text]): Text to highlight.\n\n        Raises:\n            TypeError: If not called with text or str.\n\n        Returns:\n            Text: A test instance with highlighting applied.\n        \"\"\"\n        if isinstance(text, str):\n            highlight_text = Text(text)\n        elif isinstance(text, Text):\n            highlight_text = text.copy()\n        else:\n            raise TypeError(f\"str or Text instance required, not {text!r}\")\n        self.highlight(highlight_text)\n        return highlight_text\n\n    @abstractmethod\n    def highlight(self, text: Text) -> None:\n        \"\"\"Apply highlighting in place to text.\n\n        Args:\n            text (~Text): A text object highlight.\n        \"\"\"\n\n\nclass NullHighlighter(Highlighter):\n    \"\"\"A highlighter object that doesn't highlight.\n\n    May be used to disable highlighting entirely.\n\n    \"\"\"\n\n    def highlight(self, text: Text) -> None:\n        \"\"\"Nothing to do\"\"\"\n\n\nclass RegexHighlighter(Highlighter):\n    \"\"\"Applies highlighting from a list of regular expressions.\"\"\"\n\n    highlights: List[str] = []\n    base_style: str = \"\"\n\n    def highlight(self, text: Text) -> None:\n        \"\"\"Highlight :class:`rich.text.Text` using regular expressions.\n\n        Args:\n            text (~Text): Text to highlighted.\n\n        \"\"\"\n        highlight_regex = text.highlight_regex\n        for re_highlight in self.highlights:\n            highlight_regex(re_highlight, style_prefix=self.base_style)\n\n\nclass ReprHighlighter(RegexHighlighter):\n    \"\"\"Highlights the text typically produced from ``__repr__`` methods.\"\"\"\n\n    base_style = \"repr.\"\n    highlights = [\n        r\"(?P<brace>[\\{\\[\\(\\)\\]\\}])\",\n        r\"(?P<tag_start>\\<)(?P<tag_name>[\\w\\-\\.\\:]*)(?P<tag_contents>.*?)(?P<tag_end>\\>)\",\n        r\"(?P<attrib_name>\\w+?)=(?P<attrib_value>\\\"?[\\w_]+\\\"?)\",\n        r\"(?P<bool_true>True)|(?P<bool_false>False)|(?P<none>None)\",\n        r\"(?P<number>(?<!\\w)\\-?[0-9]+\\.?[0-9]*(e[\\-\\+]?\\d+?)?\\b)\",\n        r\"(?P<number>0x[0-9a-f]*)\",\n        r\"(?P<path>\\B(\\/[\\w\\.\\-\\_\\+]+)*\\/)(?P<filename>[\\w\\.\\-\\_\\+]*)?\",\n        r\"(?<!\\\\)(?P<str>b?\\'\\'\\'.*?(?<!\\\\)\\'\\'\\'|b?\\'.*?(?<!\\\\)\\'|b?\\\"\\\"\\\".*?(?<!\\\\)\\\"\\\"\\\"|b?\\\".*?(?<!\\\\)\\\")\",\n        r\"(?P<url>https?:\\/\\/[0-9a-zA-Z\\$\\-\\_\\+\\!`\\(\\)\\,\\.\\?\\/\\;\\:\\&\\=\\%\\#]*)\",\n        r\"(?P<uuid>[a-fA-F0-9]{8}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{12})\",\n    ]\n\n\nif __name__ == \"__main__\":  # pragma: no cover\n    from .console import Console\n\n    console = Console()\n    console.print(\"[bold green]hello world![/bold green]\")\n    console.print(\"'[bold green]hello world![/bold green]'\")\n\n    console.print(\" /foo\")\n    console.print(\"/foo/\")\n    console.print(\"/foo/bar\")\n    console.print(\"foo/bar/baz\")\n\n    console.print(\"/foo/bar/baz?foo=bar+egg&egg=baz\")\n    console.print(\"/foo/bar/baz/\")\n    console.print(\"/foo/bar/baz/egg\")\n    console.print(\"/foo/bar/baz/egg.py\")\n    console.print(\"/foo/bar/baz/egg.py word\")\n    console.print(\" /foo/bar/baz/egg.py word\")\n    console.print(\"foo /foo/bar/baz/egg.py word\")\n    console.print(\"foo /foo/bar/ba._++z/egg+.py word\")\n    console.print(\"https://example.org?foo=bar#header\")\n\n    console.print(1234567.34)\n    console.print(1 / 2)\n    console.print(-1 / 123123123123)\n", "path": "rich/highlighter.py"}]}