Skip to content

Commit

Permalink
Backport PR pandas-dev#46457: BUG: url regex in style_render does n…
Browse files Browse the repository at this point in the history
…ot pass colon and other valid (pandas-dev#46497)

Co-authored-by: Kian Eliasi <kian.elbo@gmail.com>
  • Loading branch information
meeseeksmachine and kianelbo committed Mar 25, 2022
1 parent cb36d8d commit 205bb47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.4.2.rst
Expand Up @@ -31,7 +31,7 @@ Bug fixes
~~~~~~~~~
- Fix some cases for subclasses that define their ``_constructor`` properties as general callables (:issue:`46018`)
- Fixed "longtable" formatting in :meth:`.Styler.to_latex` when ``column_format`` is given in extended format (:issue:`46037`)
-
- Fixed incorrect rendering in :meth:`.Styler.format` with ``hyperlinks="html"`` when the url contains a colon or other special characters (:issue:`46389`)

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style_render.py
Expand Up @@ -1488,7 +1488,7 @@ def _render_href(x, format):
href = r"\href{{{0}}}{{{0}}}"
else:
raise ValueError("``hyperlinks`` format can only be 'html' or 'latex'")
pat = r"(https?:\/\/|ftp:\/\/|www.)[\w/\-?=%.]+\.[\w/\-&?=%.]+"
pat = r"((http|ftp)s?:\/\/|www.)[\w/\-?=%.:@]+\.[\w/\-&?=%.,':;~!@#$*()\[\]]+"
return re.sub(pat, lambda m: href.format(m.group(0)), x)
return x

Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/io/formats/style/test_html.py
Expand Up @@ -778,8 +778,20 @@ def test_hiding_index_columns_multiindex_trimming():
("no scheme, no top-level: www.web", False, "www.web"),
("https scheme: https://www.web.com", True, "https://www.web.com"),
("ftp scheme: ftp://www.web", True, "ftp://www.web"),
("ftps scheme: ftps://www.web", True, "ftps://www.web"),
("subdirectories: www.web.com/directory", True, "www.web.com/directory"),
("Multiple domains: www.1.2.3.4", True, "www.1.2.3.4"),
("with port: http://web.com:80", True, "http://web.com:80"),
(
"full net_loc scheme: http://user:pass@web.com",
True,
"http://user:pass@web.com",
),
(
"with valid special chars: http://web.com/,.':;~!@#$*()[]",
True,
"http://web.com/,.':;~!@#$*()[]",
),
],
)
def test_rendered_links(type, text, exp, found):
Expand Down

0 comments on commit 205bb47

Please sign in to comment.