Skip to content
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: allow for git usernames that start with a number #197

Merged
merged 1 commit into from
Dec 10, 2024
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://git@my.custom.git.com: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',
},

'git@github.com:12345': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://git@github.com:12345',
fetchSpec: 'ssh://git@github.com:12345',
raw: 'git@github.com:12345',
},

'git@github.com:12345/': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://git@github.com:12345/',
fetchSpec: 'ssh://git@github.com:12345/',
raw: 'git@github.com:12345/',
},

'git@github.com:12345/foo': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://git@github.com:12345/foo',
fetchSpec: 'ssh://git@github.com:12345/foo',
raw: 'git@github.com:12345/foo',
},

'git@github.com:12345foo': {
name: undefined,
type: 'git',
saveSpec: 'git+ssh://git@github.com:12345foo',
fetchSpec: 'git@github.com:12345foo',
raw: 'git@github.com:12345foo',
},
}

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