Return error if it's an invalid URL
This commit is contained in:
parent
0b8c964a41
commit
2af136cc78
1 changed files with 10 additions and 4 deletions
|
|
@ -71,10 +71,16 @@ func viewRun(opts *ViewOptions) error {
|
|||
return utils.OpenInBrowser(gistURL)
|
||||
}
|
||||
|
||||
u, err := url.Parse(opts.Selector)
|
||||
if err == nil {
|
||||
if strings.HasPrefix(u.Path, "/") {
|
||||
gistID = strings.Split(u.Path, "/")[2]
|
||||
if strings.Contains(gistID, "/") {
|
||||
u, err := url.Parse(opts.Selector)
|
||||
if err == nil && strings.HasPrefix(u.Path, "/") {
|
||||
split := strings.Split(u.Path, "/")
|
||||
|
||||
if len(split) > 2 && split[2] != "" {
|
||||
gistID = strings.Split(u.Path, "/")[2]
|
||||
} else {
|
||||
return fmt.Errorf("Invalid gist URL %s", u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue