Skip to content

Commit ea07a6e

Browse files
authored
fix: allow for git usernames that start with a number (#197)
1 parent 41aa799 commit ea07a6e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/npa.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const hasSlashes = isWindows ? /\\|[/]/ : /[/]/
1717
const isURL = /^(?:git[+])?[a-z]+:/i
1818
const isGit = /^[^@]+@[^:.]+\.[^:]+:.+$/i
1919
const isFilename = /[.](?:tgz|tar.gz|tar)$/i
20+
const isPortNumber = /:[0-9]+(\/|$)/i
2021

2122
function npa (arg, where) {
2223
let name
@@ -324,7 +325,9 @@ function fromURL (res) {
324325
// git+ssh://[email protected]:username/project.git#deadbeef
325326
// ...and various combinations. The username in the beginning is *required*.
326327
const matched = rawSpec.match(/^git\+ssh:\/\/([^:#]+:[^#]+(?:\.git)?)(?:#(.*))?$/i)
327-
if (matched && !matched[1].match(/:[0-9]+\/?.*$/i)) {
328+
// Filter out all-number "usernames" which are really port numbers
329+
// They can either be :1234 :1234/ or :1234/path but not :12abc
330+
if (matched && !matched[1].match(isPortNumber)) {
328331
res.type = 'git'
329332
setGitAttrs(res, matched[2])
330333
res.fetchSpec = matched[1]

test/github.js

+25
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,37 @@ require('tap').test('basic', function (t) {
8989
raw: 'foo@bar/foo',
9090
},
9191

92+
'[email protected]:12345': {
93+
name: undefined,
94+
type: 'git',
95+
saveSpec: 'git+ssh://[email protected]:12345',
96+
fetchSpec: 'ssh://[email protected]:12345',
97+
raw: '[email protected]:12345',
98+
},
99+
100+
'[email protected]:12345/': {
101+
name: undefined,
102+
type: 'git',
103+
saveSpec: 'git+ssh://[email protected]:12345/',
104+
fetchSpec: 'ssh://[email protected]:12345/',
105+
raw: '[email protected]:12345/',
106+
},
107+
92108
'[email protected]:12345/foo': {
93109
name: undefined,
94110
type: 'git',
95111
saveSpec: 'git+ssh://[email protected]:12345/foo',
112+
fetchSpec: 'ssh://[email protected]:12345/foo',
96113
raw: '[email protected]:12345/foo',
97114
},
115+
116+
'[email protected]:12345foo': {
117+
name: undefined,
118+
type: 'git',
119+
saveSpec: 'git+ssh://[email protected]:12345foo',
120+
fetchSpec: '[email protected]:12345foo',
121+
raw: '[email protected]:12345foo',
122+
},
98123
}
99124

100125
Object.keys(tests).forEach(function (arg) {

0 commit comments

Comments
 (0)