Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const hasSlashes = isWindows ? /\\|[/]/ : /[/]/
const isURL = /^(?:git[+])?[a-z]+:/i
const isGit = /^[^@]+@[^:.]+\.[^:]+:.+$/i
const isFilename = /[.](?:tgz|tar.gz|tar)$/i
const isPortNumber = /:[0-9]+(\/|$)/i

function npa (arg, where) {
let name
Expand Down Expand Up @@ -324,7 +325,9 @@ function fromURL (res) {
// git+ssh://[email protected]:username/project.git#deadbeef
// ...and various combinations. The username in the beginning is *required*.
const matched = rawSpec.match(/^git\+ssh:\/\/([^:#]+:[^#]+(?:\.git)?)(?:#(.*))?$/i)
if (matched && !matched[1].match(/:[0-9]+\/?.*$/i)) {
// Filter out all-number "usernames" which are really port numbers
// They can either be :1234 :1234/ or :1234/path but not :12abc
if (matched && !matched[1].match(isPortNumber)) {
res.type = 'git'
setGitAttrs(res, matched[2])
res.fetchSpec = matched[1]
Expand Down
25 changes: 25 additions & 0 deletions test/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,37 @@ require('tap').test('basic', function (t) {
raw: 'foo@bar/foo',
},

'[email protected]:12345': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://[email protected]:12345',
fetchSpec: 'ssh://[email protected]:12345',
raw: '[email protected]:12345',
},

'[email protected]:12345/': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://[email protected]:12345/',
fetchSpec: 'ssh://[email protected]:12345/',
raw: '[email protected]:12345/',
},

'[email protected]:12345/foo': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://[email protected]:12345/foo',
fetchSpec: 'ssh://[email protected]:12345/foo',
raw: '[email protected]:12345/foo',
},

'[email protected]:12345foo': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://[email protected]:12345foo',
fetchSpec: '[email protected]:12345foo',
raw: '[email protected]:12345foo',
},
}

Object.keys(tests).forEach(function (arg) {
Expand Down
Loading