Skip to content

Commit 3618f15

Browse files
Account for empty body in api/contents POST
1 parent 0c22000 commit 3618f15

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

jupyter_server/services/contents/handlers.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,23 @@ async def post(self, path=""):
208208
raise web.HTTPError(400, "Cannot POST to files, use PUT instead.")
209209

210210
model = self.get_json_body()
211-
copy_from = model.get("copy_from")
212-
if (
213-
copy_from
214-
and (
215-
await ensure_async(cm.is_hidden(path))
216-
or await ensure_async(cm.is_hidden(copy_from))
217-
)
218-
and not cm.allow_hidden
219-
):
220-
raise web.HTTPError(400, f"Cannot copy file or directory {path!r}")
221-
222-
if model is not None:
211+
if model:
223212
copy_from = model.get("copy_from")
213+
if copy_from:
214+
if not cm.allow_hidden and (
215+
await ensure_async(cm.is_hidden(path))
216+
or await ensure_async(cm.is_hidden(copy_from))
217+
):
218+
raise web.HTTPError(400, f"Cannot copy file or directory {path!r}")
219+
else:
220+
await self._copy(copy_from, path)
221+
224222
ext = model.get("ext", "")
225223
type = model.get("type", "")
226224
if type not in {None, "", "directory", "file", "notebook"}:
227225
# fall back to file if unknown type
228226
type = "file"
229-
if copy_from:
230-
await self._copy(copy_from, path)
231-
else:
232-
await self._new_untitled(path, type=type, ext=ext)
227+
await self._new_untitled(path, type=type, ext=ext)
233228
else:
234229
await self._new_untitled(path)
235230

0 commit comments

Comments
 (0)