From 24add494ae0beb2948eb376bff61be824d636484 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 Sep 2014 10:47:05 -0700 Subject: [PATCH] Normalize project path in Project::setPath This will remove consecutive slashes as well as . and .. characters and make path comparisons accurate. Closes atom/tree-view#191 --- spec/project-spec.coffee | 5 +++++ src/project.coffee | 1 + 2 files changed, 6 insertions(+) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 09ad8fb91..06e3ee29d 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -190,6 +190,11 @@ describe "Project", -> expect(atom.project.getPath()?).toBeFalsy() expect(atom.project.getRootDirectory()?).toBeFalsy() + it "normalizes the path to remove consecutive slashes, ., and .. segments", -> + atom.project.setPath("#{require.resolve('./fixtures/dir/a')}#{path.sep}b#{path.sep}#{path.sep}..") + expect(atom.project.getPath()).toEqual path.dirname(require.resolve('./fixtures/dir/a')) + expect(atom.project.getRootDirectory().path).toEqual path.dirname(require.resolve('./fixtures/dir/a')) + describe ".replace()", -> [filePath, commentFilePath, sampleContent, sampleCommentContent] = [] diff --git a/src/project.coffee b/src/project.coffee index c0b81ddd0..bf2adf2c3 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -84,6 +84,7 @@ class Project extends Model # # * `projectPath` {String} path setPath: (projectPath) -> + projectPath = path.normalize(projectPath) if projectPath @path = projectPath @rootDirectory?.off()