mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-12-28 00:52:29 +03:00
Don't modify uri's with a scheme prefix in Project.resolve
This commit is contained in:
parent
5aac826ec1
commit
aefb84cdeb
@ -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", ->
|
||||
|
@ -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.
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user