Skip to content

Commit

Permalink
Fix linkify with arrays in querystring (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
willkg committed Oct 6, 2023
1 parent 11d8c9b commit c4a4eba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bleach/linkifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def build_url_re(tlds=TLDS, protocols=html5lib_shim.allowed_protocols):
r"""\(* # Match any opening parentheses.
\b(?<![@.])(?:(?:{0}):/{{0,3}}(?:(?:\w+:)?\w+@)?)? # http://
([\w-]+\.)+(?:{1})(?:\:[0-9]+)?(?!\.\w)\b # xx.yy.tld(:##)?
(?:[/?][^\s\{{\}}\|\\\^\[\]`<>"]*)?
# /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))
Expand Down
8 changes: 8 additions & 0 deletions tests/test_linkify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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&params_in[]=2") == (
'<a href="http://test.com?array[]=1&amp;params_in[]=2" '
+ 'rel="nofollow">http://test.com?array[]=1&amp;params_in[]=2</a>'
)


def test_link_query():
assert (
linkify("http://xx.com/?test=win")
Expand Down

0 comments on commit c4a4eba

Please sign in to comment.