diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index ce2a88e74..6367e20c4 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -99,12 +99,17 @@ describe "Project", -> buffer = project.bufferForPath("a").retain().release() expect(project.bufferForPath("a").retain().release()).not.toBe buffer - describe ".resolve(path)", -> - it "returns an absolute path based on the project's root", -> - absolutePath = fsUtils.resolveOnLoadPath('fixtures/dir/a') - expect(project.resolve('a')).toBe absolutePath - expect(project.resolve(absolutePath + '/../a')).toBe absolutePath - expect(project.resolve('a/../a')).toBe absolutePath + describe ".resolve(uri)", -> + describe "when passed an absolute or relative path", -> + it "returns an absolute path based on the project's root", -> + absolutePath = fsUtils.resolveOnLoadPath('fixtures/dir/a') + expect(project.resolve('a')).toBe absolutePath + expect(project.resolve(absolutePath + '/../a')).toBe absolutePath + expect(project.resolve('a/../a')).toBe absolutePath + + describe "when passed a uri with a scheme", -> + it "does not modify uris that begin with a scheme", -> + expect(project.resolve('http://zombo.com')).toBe 'http://zombo.com' describe ".relativize(path)", -> it "returns an relative path based on the project's root", -> diff --git a/src/app/project.coffee b/src/app/project.coffee index 5dd65681a..146894caa 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -111,14 +111,18 @@ class Project ignoreRepositoryPath: (path) -> config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fsUtils.join(@getPath(), path)) - # Given a path, this resolves it relative to the project directory. + # Given a uri, this resolves it relative to the project directory. If the path + # is already absolute or if it is prefixed with a scheme, it is returned unchanged. # - # filePath - The {String} name of the path to convert + # uri - The {String} name of the path to convert # # Returns a {String}. - resolve: (filePath) -> - filePath = fsUtils.join(@getPath(), filePath) unless filePath[0] == '/' - fsUtils.absolute filePath + resolve: (uri) -> + if uri?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme + uri + else + uri = fsUtils.join(@getPath(), uri) unless uri[0] == '/' + fsUtils.absolute uri # Given a path, this makes it relative to the project directory. #