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
This commit is contained in:
Kevin Sawicki
2014-09-02 10:47:05 -07:00
parent c5aa446bc2
commit 24add494ae
2 changed files with 6 additions and 0 deletions

View File

@@ -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] = []

View File

@@ -84,6 +84,7 @@ class Project extends Model
#
# * `projectPath` {String} path
setPath: (projectPath) ->
projectPath = path.normalize(projectPath) if projectPath
@path = projectPath
@rootDirectory?.off()