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 regex to match HTTPS as well for getHostname #7

Merged
merged 2 commits into from
Nov 8, 2021
Merged

Fix regex to match HTTPS as well for getHostname #7

merged 2 commits into from
Nov 8, 2021

Conversation

ken-matsui
Copy link
Contributor

Currently, GitHub has two types of URLs: one is SSH, another is HTTPS. The getHostname function seems not to support HTTPS URL; therefore, gh-poi panics due to no matches in case of using HTTPS URL.

⠋ Fetching pull requests... panic: runtime error: index out of range [1] with length 0

goroutine 1 [running]:
main.getHostname({0x1400017a000, 0x6f})
        /home/runner/work/gh-poi/gh-poi/poi.go:106 +0xc4
main.GetBranches({0x100dc2d18, 0x100ea22f0})
        /home/runner/work/gh-poi/gh-poi/poi.go:67 +0x5c
main.main()
        /home/runner/work/gh-poi/gh-poi/main.go:38 +0x278

This PR brings a new regex that matches also HTTPS. You can check it out on regex101.com.

Copy link
Owner

@seachicken seachicken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about the https, thanks!

poi.go Outdated
@@ -101,9 +101,9 @@ func GetBranches(conn Connection) ([]Branch, error) {
}

func getHostname(remoteName string) string {
r := regexp.MustCompile("(?:@|//)(.+):")
r := regexp.MustCompile("(@|//)(.+?)(:|/)")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are only interested in the hostname, so we don't need to capture the group.
In that case, we can leave the found[1] code as it is.

Suggested change
r := regexp.MustCompile("(@|//)(.+?)(:|/)")
r := regexp.MustCompile("(?:@|//)(.+?)(?::|/)")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seachicken
I did not know the no-capturing group. Thanks :)

@ken-matsui
Copy link
Contributor Author

@seachicken
Would you like me to squash commits into one?

@seachicken
Copy link
Owner

Don't worry about it. I do "Squash and merge".
I'll release this fix soon as there are some users who need it. Thank you.

@seachicken seachicken merged commit bc19442 into seachicken:main Nov 8, 2021
@ken-matsui ken-matsui deleted the fix-regex-for-hostname branch November 8, 2021 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants