Skip to content

Commit ba9cc9a

Browse files
committed
BUG: url regex in style_render does not pass colon and other valid
URLs containing some valid characters such as colon in port numbers get cut off when html-formatting. As a workaround, expanded the regex to match a wider variety of URLs.
1 parent 6033ed4 commit ba9cc9a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/io/formats/style_render.py

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

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)