Skip to content

Commit 8010415

Browse files
committed
paths: fix dirname for paths that end in slash. Explorer model fix find for paths ending with extra slashes
fixes microsoft/vscode-cascade#57
1 parent 2ed98bf commit 8010415

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/vs/base/common/paths.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export function dirname(path: string): string {
2727
return '.';
2828
} else if (~idx === 0) {
2929
return path[0];
30+
} else if (~idx === path.length - 1) {
31+
return dirname(path.substring(0, path.length - 1));
3032
} else {
3133
let res = path.substring(0, ~idx);
3234
if (isWindows && res[res.length - 1] === ':') {
@@ -395,4 +397,4 @@ export function isAbsolute_win32(path: string): boolean {
395397

396398
export function isAbsolute_posix(path: string): boolean {
397399
return path && path.charCodeAt(0) === CharCode.Slash;
398-
}
400+
}

src/vs/base/test/common/paths.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ suite('Paths', () => {
2020
assert.equal(paths.dirname('/'), '/');
2121
assert.equal(paths.dirname('\\'), '\\');
2222
assert.equal(paths.dirname('foo'), '.');
23+
assert.equal(paths.dirname('/folder/'), '/');
2324
if (platform.isWindows) {
2425
assert.equal(paths.dirname('c:\\some\\file.txt'), 'c:\\some');
2526
assert.equal(paths.dirname('c:\\some'), 'c:\\');
@@ -226,4 +227,4 @@ suite('Paths', () => {
226227
assert.ok(!paths.isAbsolute_posix(nonAbsolutePath), nonAbsolutePath);
227228
});
228229
});
229-
});
230+
});

src/vs/workbench/parts/files/common/explorerModel.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { IEditorGroup, toResource, IEditorIdentifier } from 'vs/workbench/common
1717
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
1818
import { getPathLabel } from 'vs/base/common/labels';
1919
import { Schemas } from 'vs/base/common/network';
20-
import { startsWith, startsWithIgnoreCase, equalsIgnoreCase } from 'vs/base/common/strings';
20+
import { startsWith, startsWithIgnoreCase, equalsIgnoreCase, rtrim } from 'vs/base/common/strings';
2121

2222
export class Model {
2323

@@ -345,10 +345,7 @@ export class ExplorerItem {
345345
}
346346

347347
private findByPath(path: string, index: number): ExplorerItem {
348-
if (this.resource.path === path) {
349-
return this;
350-
}
351-
if (!isLinux && equalsIgnoreCase(this.resource.path, path)) {
348+
if (paths.isEqual(rtrim(this.resource.path, paths.sep), rtrim(path, paths.sep), !isLinux)) {
352349
return this;
353350
}
354351

src/vs/workbench/parts/files/test/electron-browser/explorerModel.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ suite('Files - View Model', () => {
156156
assert.strictEqual(s1.find(toResource('foobar')), null);
157157

158158
assert.strictEqual(s1.find(toResource('/')), s1);
159+
assert.strictEqual(s1.find(toResource('')), s1);
159160
});
160161

161162
test('Find with mixed case', function () {

0 commit comments

Comments
 (0)