Skip to content

Commit 205bb47

Browse files
Backport PR #46457: BUG: url regex in style_render does not pass colon and other valid (#46497)
Co-authored-by: Kian Eliasi <[email protected]>
1 parent cb36d8d commit 205bb47

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/source/whatsnew/v1.4.2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Bug fixes
3131
~~~~~~~~~
3232
- Fix some cases for subclasses that define their ``_constructor`` properties as general callables (:issue:`46018`)
3333
- Fixed "longtable" formatting in :meth:`.Styler.to_latex` when ``column_format`` is given in extended format (:issue:`46037`)
34-
-
34+
- Fixed incorrect rendering in :meth:`.Styler.format` with ``hyperlinks="html"`` when the url contains a colon or other special characters (:issue:`46389`)
3535

3636
.. ---------------------------------------------------------------------------
3737

pandas/io/formats/style_render.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ def _render_href(x, format):
14881488
href = r"\href{{{0}}}{{{0}}}"
14891489
else:
14901490
raise ValueError("``hyperlinks`` format can only be 'html' or 'latex'")
1491-
pat = r"(https?:\/\/|ftp:\/\/|www.)[\w/\-?=%.]+\.[\w/\-&?=%.]+"
1491+
pat = r"((http|ftp)s?:\/\/|www.)[\w/\-?=%.:@]+\.[\w/\-&?=%.,':;~!@#$*()\[\]]+"
14921492
return re.sub(pat, lambda m: href.format(m.group(0)), x)
14931493
return x
14941494

pandas/tests/io/formats/style/test_html.py

+12
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,20 @@ def test_hiding_index_columns_multiindex_trimming():
778778
("no scheme, no top-level: www.web", False, "www.web"),
779779
("https scheme: https://www.web.com", True, "https://www.web.com"),
780780
("ftp scheme: ftp://www.web", True, "ftp://www.web"),
781+
("ftps scheme: ftps://www.web", True, "ftps://www.web"),
781782
("subdirectories: www.web.com/directory", True, "www.web.com/directory"),
782783
("Multiple domains: www.1.2.3.4", True, "www.1.2.3.4"),
784+
("with port: http://web.com:80", True, "http://web.com:80"),
785+
(
786+
"full net_loc scheme: http://user:[email protected]",
787+
True,
788+
"http://user:[email protected]",
789+
),
790+
(
791+
"with valid special chars: http://web.com/,.':;~!@#$*()[]",
792+
True,
793+
"http://web.com/,.':;~!@#$*()[]",
794+
),
783795
],
784796
)
785797
def test_rendered_links(type, text, exp, found):

0 commit comments

Comments
 (0)