Skip to content

Commit d688715

Browse files
committed
BUG: url regex in style_render does not pass colon and other valid
characters 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 d688715

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-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"(https?:\/\/|ftp:\/\/|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

+2
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,8 @@ def test_hiding_index_columns_multiindex_trimming():
780780
("ftp scheme: ftp://www.web", True, "ftp://www.web"),
781781
("subdirectories: www.web.com/directory", True, "www.web.com/directory"),
782782
("Multiple domains: www.1.2.3.4", True, "www.1.2.3.4"),
783+
("with port: http://web.com:80", True, "http://web.com:80"),
784+
("with anchor: http://web.com/anc#hor", True, "http://web.com/anc#hor"),
783785
],
784786
)
785787
def test_rendered_links(type, text, exp, found):

0 commit comments

Comments
 (0)