Kaynağa Gözat

Merge pull request #2388 from ian-r-rose/dirname_again

Catch the `dirname` case of a file in the root directory.
Steven Silvester 8 yıl önce
ebeveyn
işleme
14b33e084c

+ 2 - 4
packages/coreutils/src/path.ts

@@ -44,10 +44,8 @@ namespace PathExt {
    */
   export
   function dirname(path: string): string {
-    if (path === '') {
-      return '';
-    }
-    return removeSlash(posix.dirname(path));
+    let dir = removeSlash(posix.dirname(path));
+    return dir === '.' ? '' : dir;
   }
 
   /**

+ 1 - 1
packages/filebrowser/src/model.ts

@@ -382,7 +382,7 @@ class FileBrowserModel implements IDisposable {
    * Handle a change on the contents manager.
    */
   private _onFileChanged(sender: Contents.IManager, change: Contents.IChangedArgs): void {
-    let path = this._model.path || '.';
+    let path = this._model.path;
     let value = change.oldValue;
     if (value && value.path && PathExt.dirname(value.path) === path) {
       this._fileChanged.emit(change);

+ 5 - 0
test/src/coreutils/path.spec.ts

@@ -45,6 +45,11 @@ describe('@jupyterlab/coreutils', () => {
         expect(path).to.equal('');
       });
 
+      it('should not return "." for a path in the root directory', () => {
+        let path = PathExt.dirname('foo.txt');
+        expect(path).to.equal('');
+      });
+
     });
 
     describe('.extname()', () => {