From a9adfa6a76e972b1d8b2fbb5ef1f4b9932e3d6f8 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 18 Feb 2015 16:47:21 -0800 Subject: [PATCH] Fix bug in Project::relativize --- spec/project-spec.coffee | 6 ++++++ src/project.coffee | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index a1e503751..a4e6c0a03 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -332,10 +332,16 @@ describe "Project", -> describe ".relativize(path)", -> it "returns the path, relative to whichever root directory it is inside of", -> + atom.project.addPath(temp.mkdirSync("another-path")) + rootPath = atom.project.getPaths()[0] childPath = path.join(rootPath, "some", "child", "directory") expect(atom.project.relativize(childPath)).toBe path.join("some", "child", "directory") + rootPath = atom.project.getPaths()[1] + childPath = path.join(rootPath, "some", "child", "directory") + expect(atom.project.relativize(childPath)).toBe path.join("some", "child", "directory") + it "returns the given path if it is not in any of the root directories", -> randomPath = path.join("some", "random", "path") expect(atom.project.relativize(randomPath)).toBe randomPath diff --git a/src/project.coffee b/src/project.coffee index 4615a01b0..ac2242a28 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -241,8 +241,8 @@ class Project extends Model relativize: (fullPath) -> return fullPath if fullPath?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme for rootDirectory in @rootDirectories - if (relativePath = rootDirectory.relativize(fullPath))? - return relativePath + relativePath = rootDirectory.relativize(fullPath) + return relativePath if relativePath isnt fullPath fullPath # Public: Determines whether the given path (real or symbolic) is inside the