Skip to content

Commit

Permalink
fix: allow for git usernames that start with a number (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored Dec 10, 2024
1 parent 41aa799 commit ea07a6e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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

0 comments on commit ea07a6e

Please sign in to comment.