Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linkify with arrays in querystring (#436) #722

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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