Skip to content

Commit 61ca7fb

Browse files
committed
fix: parse branch names containing @
1 parent 3cd4a98 commit 61ca7fb

File tree

2 files changed

+63
-58
lines changed

2 files changed

+63
-58
lines changed

lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function protocolToRepresentation (protocol) {
1717
}
1818

1919
function lastIndexOfBefore (str, char, beforeChar) {
20-
const startPosition = str.lastIndexOf(beforeChar)
20+
const startPosition = str.indexOf(beforeChar)
2121
return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity)
2222
}
2323

@@ -193,7 +193,9 @@ const isGitHubShorthand = (arg) => {
193193

194194
// attempt to correct an scp style url so that it will parse with `new URL()`
195195
const correctUrl = (giturl) => {
196-
const firstAt = giturl.indexOf('@')
196+
// ignore @ that come after the first hash since the denotes the start
197+
// of a committish which can contain @ characters
198+
const firstAt = lastIndexOfBefore(giturl, '@', '#')
197199
// ignore colons that come after the hash since that could include colons such as:
198200
// git@github.com:user/package-2#semver:^1.0.0
199201
const lastColonBeforeHash = lastIndexOfBefore(giturl, ':', '#')

0 commit comments

Comments
 (0)