Explorar o código

Take care of trailing slashes in the open path code.

Jason Grout %!s(int64=5) %!d(string=hai) anos
pai
achega
24febd58b3
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      packages/filebrowser-extension/src/index.ts

+ 12 - 2
packages/filebrowser-extension/src/index.ts

@@ -453,7 +453,7 @@ function addCommands(
     label: 'Open From Path…',
     caption: 'Open from path',
     execute: async () => {
-      const { value: path } = await InputDialog.getText({
+      let { value: path } = await InputDialog.getText({
         label: 'Path',
         placeholder: '/path/relative/to/jlab/root',
         title: 'Open Path',
@@ -463,9 +463,19 @@ function addCommands(
         return;
       }
       try {
-        const item = await docManager.services.contents.get(path, {
+        let trailingSlash = path !== '/' && path.endsWith('/');
+        if (trailingSlash) {
+          // The normal contents service errors on paths ending in slash
+          path = path.slice(0, path.length - 1);
+        }
+        const browserForPath = Private.getBrowserForPath(path, factory);
+        const { services } = browserForPath.model.manager;
+        const item = await services.contents.get(path, {
           content: false
         });
+        if (trailingSlash && item.type !== 'directory') {
+          throw new Error(`Path ${path}/ is not a directory`);
+        }
         await commands.execute(CommandIDs.goToPath, { path });
         if (item.type === 'directory') {
           return;