From 08b0a686edb87275f0d39331a802295b1b5c4587 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 3 Jul 2012 14:43:56 -0700 Subject: [PATCH] fs.directory returns empty string if path has no parent directory --- spec/stdlib/fs-spec.coffee | 5 +++-- src/stdlib/fs.coffee | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index ad7c29bd9..1ee172c8d 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -21,8 +21,9 @@ describe "fs", -> describe "when called with a directory path", -> it "return the path it was given", -> - expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures') - expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures') + expect(fs.directory("/a/b/c")).toBe "/a/b" + expect(fs.directory("/a")).toBe "" + expect(fs.directory("a")).toBe "" describe ".exists(path)", -> it "returns true when path exsits", -> diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index b873e453f..f39dca80b 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -21,7 +21,9 @@ module.exports = # parent directory if the file is a directory. A terminal directory # separator is ignored. directory: (path) -> - path.replace(new RegExp("/#{@base(path)}\/?$"), '') + parentPath = path.replace(new RegExp("/#{@base(path)}\/?$"), '') + return "" if path == parentPath + parentPath # Returns true if the file specified by path exists exists: (path) ->