提交 f2b3fd88 编写于 作者: M Mislav Marohnić

Avoid crashing on invalid GitHub hostname

Fixes #2022
上级 08004b92
......@@ -274,3 +274,28 @@ Feature: hub create
< Location: http://disney.com
{"full_name":"mislav/dotfiles"}\n
"""
Scenario: Create Enterprise repo
Given I am "nsartor" on git.my.org with OAuth token "FITOKEN"
Given the GitHub API server:
"""
post('/api/v3/user/repos', :host_name => 'git.my.org') {
assert :private => false
status 201
json :full_name => 'nsartor/dotfiles'
}
"""
And $GITHUB_HOST is "git.my.org"
When I successfully run `hub create`
Then the url for "origin" should be "git@git.my.org:nsartor/dotfiles.git"
And the output should contain exactly "https://git.my.org/nsartor/dotfiles\n"
Scenario: Invalid GITHUB_HOST
Given I am "nsartor" on {} with OAuth token "FITOKEN"
And $GITHUB_HOST is "{}"
When I run `hub create`
Then the exit status should be 1
And the stderr should contain exactly:
"""
invalid hostname: "{}"\n
"""
......@@ -992,8 +992,10 @@ func (client *Client) apiClient() *simpleClient {
}
func (client *Client) absolute(host string) *url.URL {
u, _ := url.Parse("https://" + host + "/")
if client.Host != nil && client.Host.Protocol != "" {
u, err := url.Parse("https://" + host + "/")
if err != nil {
panic(err)
} else if client.Host != nil && client.Host.Protocol != "" {
u.Scheme = client.Host.Protocol
}
return u
......
......@@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/signal"
"path/filepath"
......@@ -40,6 +41,13 @@ func (c *Config) PromptForHost(host string) (h *Host, err error) {
token := c.DetectToken()
tokenFromEnv := token != ""
if host != GitHubHost {
if _, e := url.Parse("https://" + host); e != nil {
err = fmt.Errorf("invalid hostname: %q", host)
return
}
}
h = c.Find(host)
if h != nil {
if h.User == "" {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册