-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix private urls using colon separator #2519
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* @flow */ | ||
|
||
import {parse} from 'url'; | ||
|
||
import GitResolver from '../../../src/resolvers/exotics/git-resolver.js'; | ||
|
||
test('GitResolver transformUrl method is defined', () => { | ||
expect(GitResolver.transformUrl).toBeDefined(); | ||
}); | ||
|
||
test('GitResolver transformUrl does not affect normal urls', () => { | ||
|
||
const urls = [ | ||
'git+https://github.com/npm-ml/ocaml.git#npm-4.02.3', | ||
'git+ssh://[email protected]/user/repo.git', | ||
'git+ssh://[email protected]/user/repo.git', | ||
'git+ssh://[email protected]/sub/right-pad', | ||
'https://github.com/npm-ml/re', | ||
'https://github.com/npm-ml/ocaml.git#npm-4.02.3', | ||
'https://[email protected]/stevemao/left-pad.git', | ||
'https://bitbucket.org/hgarcia/node-bitbucket-api.git', | ||
'https://github.com/yarnpkg/yarn/releases/download/v0.18.1/yarn-v0.18.1.tar.gz', | ||
'https://github.com/babel/babel-loader.git#greenkeeper/cross-env-3.1.4', | ||
'package@[email protected]:team/repo.git', | ||
]; | ||
|
||
urls.forEach((url) => { | ||
expect(GitResolver.transformUrl(parse(url))).toBe(url); | ||
}); | ||
|
||
}); | ||
|
||
test('GitResolver transformUrl affect host colon separated urls', () => { | ||
|
||
const urls = [ | ||
'git+ssh://[email protected]:sub/right-pad', | ||
'git+ssh://private.url:sub/right-pad', | ||
'https://private.url:sub/right-pad', | ||
]; | ||
|
||
urls.forEach((url) => { | ||
expect(GitResolver.transformUrl(parse(url))).toBe(url.replace(':sub', '/sub')); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ExoticResolver from './exotic-resolver.js'; | |
import Git from '../../util/git.js'; | ||
|
||
const urlParse = require('url').parse; | ||
const urlFormat = require('url').format; | ||
|
||
// we purposefully omit https and http as those are only valid if they end in the .git extension | ||
const GIT_PROTOCOLS = ['git:', 'git+ssh:', 'git+https:', 'ssh:']; | ||
|
@@ -60,6 +61,14 @@ export default class GitResolver extends ExoticResolver { | |
return false; | ||
} | ||
|
||
// This transformUrl util is here to replace colon separators in the pathname | ||
// from private urls. It takes the url parts retrieved using urlFormat and | ||
// returns the associated url. Related to #573, introduced in #2519. | ||
static transformUrl(parts) : string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can probably come up with a more descriptive name than "transform." |
||
const pathname = parts.pathname ? parts.pathname.replace(/^\/:/, '/') : ''; | ||
return urlFormat({...parts, pathname}); | ||
} | ||
|
||
async resolve(forked?: true): Promise<Manifest> { | ||
const {url} = this; | ||
|
||
|
@@ -92,7 +101,10 @@ export default class GitResolver extends ExoticResolver { | |
} | ||
|
||
const {config} = this; | ||
const client = new Git(config, url, this.hash); | ||
|
||
const transformedUrl = GitResolver.transformUrl(parts); | ||
|
||
const client = new Git(config, transformedUrl, this.hash); | ||
const commit = await client.init(); | ||
|
||
async function tryRegistry(registry): Promise<?Manifest> { | ||
|
@@ -103,12 +115,12 @@ export default class GitResolver extends ExoticResolver { | |
return null; | ||
} | ||
|
||
const json = await config.readJson(`${url}/${filename}`, () => JSON.parse(file)); | ||
const json = await config.readJson(`${transformedUrl}/${filename}`, () => JSON.parse(file)); | ||
json._uid = commit; | ||
json._remote = { | ||
resolved: `${url}#${commit}`, | ||
resolved: `${transformedUrl}#${commit}`, | ||
type: 'git', | ||
reference: url, | ||
reference: transformedUrl, | ||
hash: commit, | ||
registry, | ||
}; | ||
|
@@ -131,6 +143,6 @@ export default class GitResolver extends ExoticResolver { | |
} | ||
} | ||
|
||
throw new MessageError(this.reporter.lang('couldntFindManifestIn', url)); | ||
throw new MessageError(this.reporter.lang('couldntFindManifestIn', transformedUrl)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this
'GitResolver transformUrl replaces the colon on colon separated urls'
?