Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fbe14d

Browse files
committed
FileLink: escape HTML unsafe characters from path
path could contain HTML unsafe characters such as &, ', " or even < and > on Unix, so they should be escaped before putting it into HTML code both as text and the href attribute.
1 parent c043384 commit 4fbe14d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

IPython/lib/display.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Authors : MinRK, gregcaporaso, dannystaple
44
"""
5+
from html import escape as html_escape
56
from os.path import exists, isfile, splitext, abspath, join, isdir
67
from os import walk, sep, fsdecode
78

@@ -340,9 +341,10 @@ def __init__(self,
340341
self.result_html_suffix = result_html_suffix
341342

342343
def _format_path(self):
343-
fp = ''.join([self.url_prefix,self.path])
344+
fp = ''.join([self.url_prefix, html_escape(self.path)])
344345
return ''.join([self.result_html_prefix,
345-
self.html_link_str % (fp, self.path),
346+
self.html_link_str % \
347+
(fp, html_escape(self.path, quote=False)),
346348
self.result_html_suffix])
347349

348350
def _repr_html_(self):

0 commit comments

Comments
 (0)