Skip to content

Commit 2af136c

Browse files
committed
Return error if it's an invalid URL
1 parent 0b8c964 commit 2af136c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/cmd/gist/view/view.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ func viewRun(opts *ViewOptions) error {
7171
return utils.OpenInBrowser(gistURL)
7272
}
7373

74-
u, err := url.Parse(opts.Selector)
75-
if err == nil {
76-
if strings.HasPrefix(u.Path, "/") {
77-
gistID = strings.Split(u.Path, "/")[2]
74+
if strings.Contains(gistID, "/") {
75+
u, err := url.Parse(opts.Selector)
76+
if err == nil && strings.HasPrefix(u.Path, "/") {
77+
split := strings.Split(u.Path, "/")
78+
79+
if len(split) > 2 && split[2] != "" {
80+
gistID = strings.Split(u.Path, "/")[2]
81+
} else {
82+
return fmt.Errorf("Invalid gist URL %s", u)
83+
}
7884
}
7985
}
8086

0 commit comments

Comments
 (0)