From c4a4eba4a31c43d71bbf4c64ae712d230b4fd001 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Fri, 6 Oct 2023 14:08:18 -0400 Subject: [PATCH] Fix linkify with arrays in querystring (#436) --- bleach/linkifier.py | 4 ++-- tests/test_linkify.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bleach/linkifier.py b/bleach/linkifier.py index 54a432e1..8fcefb2c 100644 --- a/bleach/linkifier.py +++ b/bleach/linkifier.py @@ -45,8 +45,8 @@ def build_url_re(tlds=TLDS, protocols=html5lib_shim.allowed_protocols): r"""\(* # Match any opening parentheses. \b(?"]*)? - # /path/zz (excluding "unsafe" chars from RFC 1738, + (?:[/?][^\s\{{\}}\|\\\^`<>"]*)? + # /path/zz (excluding "unsafe" chars from RFC 3986, # except for # and ~, which happen in practice) """.format( "|".join(sorted(protocols)), "|".join(sorted(tlds)) diff --git a/tests/test_linkify.py b/tests/test_linkify.py index 4cc01a6f..0920c470 100644 --- a/tests/test_linkify.py +++ b/tests/test_linkify.py @@ -300,6 +300,14 @@ def test_link_ftp(): ) +def test_link_with_qs_with_array(): + """Test that urls pick up [] in querystring""" + assert linkify("http://test.com?array[]=1¶ms_in[]=2") == ( + 'http://test.com?array[]=1&params_in[]=2' + ) + + def test_link_query(): assert ( linkify("http://xx.com/?test=win")