Skip to content

Commit 3f7f56a

Browse files
committed
Merge pull request adobe#5907 from adobe/iwehrman/issue-5891
Make FileSystemEntry.parentPath null for root directories
2 parents e318fcd + 4435e34 commit 3f7f56a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/filesystem/FileSystemEntry.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ define(function (require, exports, module) {
138138
}
139139
this._name = parts[parts.length - 1];
140140
parts.pop(); // Remove name
141-
this._parentPath = parts.join("/") + "/";
141+
142+
if (parts.length > 0) {
143+
this._parentPath = parts.join("/") + "/";
144+
} else {
145+
// root directories have no parent path
146+
this._parentPath = null;
147+
}
142148

143149
this._path = newPath;
144150
};

test/spec/FileSystem-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,20 @@ define(function (require, exports, module) {
197197
expect(file.name).toBe("file3.txt");
198198
expect(directory.name).toBe("foo");
199199
});
200-
it("should have a parentPath property", function () {
200+
it("should have a parentPath property if it is not a root directory", function () {
201201
var file = fileSystem.getFileForPath("/subdir/file3.txt"),
202202
directory = fileSystem.getDirectoryForPath("/subdir/foo/");
203203

204204
expect(file.parentPath).toBe("/subdir/");
205205
expect(directory.parentPath).toBe("/subdir/");
206206
});
207+
it("should not have a parentPath property if it is a root directory", function () {
208+
var unixRootDir = fileSystem.getDirectoryForPath("/"),
209+
winRootDir = fileSystem.getDirectoryForPath("B:");
210+
211+
expect(unixRootDir.parentPath).toBeNull();
212+
expect(winRootDir.parentPath).toBeNull();
213+
});
207214
});
208215

209216
describe("Singleton enforcement", function () {

0 commit comments

Comments
 (0)