Fix viewing HTML in sandboxed iframe

See gh-2203

The URL calculation was going wrong, so it was using a URL starting with
//files. This uses url_path_join() to get the separators right.
This commit is contained in:
Thomas Kluyver 2017-02-20 13:28:06 +00:00
parent c305d8fda3
commit f384662df4
2 changed files with 4 additions and 3 deletions

View File

@ -23,7 +23,7 @@
} }
</style> </style>
<div id="container"> <div id="container">
<iframe id="iframe" sandbox="allow-scripts" src="{{base_url}}/files/{{file_path}}"></iframe> <iframe id="iframe" sandbox="allow-scripts" src="{{file_url}}"></iframe>
</div> </div>
</body> </body>

View File

@ -6,7 +6,7 @@
from tornado import web from tornado import web
from ..base.handlers import IPythonHandler, path_regex from ..base.handlers import IPythonHandler, path_regex
from ..utils import url_escape from ..utils import url_escape, url_path_join
class ViewHandler(IPythonHandler): class ViewHandler(IPythonHandler):
"""Render HTML files within an iframe.""" """Render HTML files within an iframe."""
@ -17,8 +17,9 @@ class ViewHandler(IPythonHandler):
raise web.HTTPError(404, u'File does not exist: %s' % path) raise web.HTTPError(404, u'File does not exist: %s' % path)
basename = path.rsplit('/', 1)[-1] basename = path.rsplit('/', 1)[-1]
file_url = url_path_join(self.base_url, 'files', path)
self.write( self.write(
self.render_template('view.html', file_path=url_escape(path), page_title=basename) self.render_template('view.html', file_url=file_url, page_title=basename)
) )
default_handlers = [ default_handlers = [