Skip to content

Commit

Permalink
fix: parse branch names containing @
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Oct 12, 2022
1 parent 3cd4a98 commit 61ca7fb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 58 deletions.
6 changes: 4 additions & 2 deletions lib/index.js
Expand Up @@ -17,7 +17,7 @@ function protocolToRepresentation (protocol) {
}

function lastIndexOfBefore (str, char, beforeChar) {
const startPosition = str.lastIndexOf(beforeChar)
const startPosition = str.indexOf(beforeChar)
return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity)
}

Expand Down Expand Up @@ -193,7 +193,9 @@ const isGitHubShorthand = (arg) => {

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

0 comments on commit 61ca7fb

Please sign in to comment.