Escape workflow information when generating URLs

This commit is contained in:
Sam Coe 2021-11-18 12:17:59 -08:00
parent 2580a63a44
commit 03278453db
No known key found for this signature in database
GPG key ID: 8E322C20F811D086

View file

@ -3,6 +3,7 @@ package view
import (
"fmt"
"net/http"
"net/url"
"strings"
"github.com/MakeNowJust/heredoc"
@ -101,7 +102,7 @@ func runView(opts *ViewOptions) error {
}
if opts.Web {
var url string
var address string
if opts.YAML {
ref := opts.Ref
if ref == "" {
@ -112,14 +113,14 @@ func runView(opts *ViewOptions) error {
return err
}
}
url = ghrepo.GenerateRepoURL(repo, "blob/%s/%s", ref, workflow.Path)
address = ghrepo.GenerateRepoURL(repo, "blob/%s/%s", url.QueryEscape(ref), url.QueryEscape(workflow.Path))
} else {
url = ghrepo.GenerateRepoURL(repo, "actions/workflows/%s", workflow.Base())
address = ghrepo.GenerateRepoURL(repo, "actions/workflows/%s", url.QueryEscape(workflow.Base()))
}
if opts.IO.IsStdoutTTY() {
fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", utils.DisplayURL(url))
fmt.Fprintf(opts.IO.Out, "Opening %s in your browser.\n", utils.DisplayURL(address))
}
return opts.Browser.Browse(url)
return opts.Browser.Browse(address)
}
if opts.YAML {