File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -203,8 +203,16 @@ class NotebookHandler(NotebookBaseHandler):
203203 """A notebook page handler."""
204204
205205 @web .authenticated
206- def get (self , path : str | None = None ) -> t .Any : # noqa: ARG002
207- """Get the notebook page."""
206+ async def get (self , path : str = "" ) -> t .Any :
207+ """Get the notebook page. Redirect if it's a directory."""
208+ path = path .strip ("/" )
209+ cm = self .contents_manager
210+
211+ if await ensure_async (cm .dir_exists (path = path )):
212+ url = ujoin (self .base_url , "tree" , url_escape (path ))
213+ self .log .debug ("Redirecting %s to %s since path is a directory" , self .request .path , url )
214+ self .redirect (url )
215+ return None
208216 tpl = self .render_template ("notebooks.html" , page_config = self .get_page_config ())
209217 return self .write (tpl )
210218
Original file line number Diff line number Diff line change 33import pytest
44from tornado .httpclient import HTTPClientError
55
6- from notebook .app import JupyterNotebookApp , TreeHandler
6+ from notebook .app import JupyterNotebookApp , NotebookHandler , TreeHandler
77
88
99@pytest .fixture ()
@@ -32,6 +32,16 @@ async def test_notebook_handler(notebooks, jp_fetch):
3232 html = r .body .decode ()
3333 assert "Jupyter Notebook" in html
3434
35+ redirected_url = None
36+
37+ def redirect (self , url ):
38+ nonlocal redirected_url
39+ redirected_url = url
40+
41+ NotebookHandler .redirect = redirect
42+ await jp_fetch ("notebooks" , "jlab_test_notebooks" )
43+ assert redirected_url == "/a%40b/tree/jlab_test_notebooks"
44+
3545
3646async def test_tree_handler (notebooks , notebookapp , jp_fetch ):
3747 app : JupyterNotebookApp = notebookapp
You can’t perform that action at this time.
0 commit comments