Skip to content

Commit cc8334e

Browse files
authored
Convert IFrame sources to strings before HTML escaping (#15348)
1 parent 82a902e commit cc8334e

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎IPython/lib/display.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _repr_html_(self):
292292
else:
293293
params = ""
294294
return self.iframe.format(
295-
src=html_escape(self.src),
295+
src=html_escape(str(self.src)),
296296
width=html_escape(str(self.width)),
297297
height=html_escape(str(self.height)),
298298
params=params,

‎tests/test_display_2.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import sys
77
import warnings
8+
from pathlib import Path
89

910
from unittest import mock
1011

@@ -595,6 +596,12 @@ def test_iframe_escaping():
595596
assert 'width="400" onload="alert(1)"' in html._repr_html_()
596597

597598

599+
def test_iframe_path_source():
600+
"""IFrame: pathlib sources are converted to strings before escaping."""
601+
html = display.IFrame(Path("report&notes.html"), 400, 300)._repr_html_()
602+
assert 'src="report&notes.html"' in html
603+
604+
598605
def test_image_bad_filename_raises_proper_exception():
599606
with pytest.raises(FileNotFoundError):
600607
display.Image("/this/file/does/not/exist/")._repr_png_()

0 commit comments

Comments
 (0)