MCPcopy Create free account
hub / github.com/cli/cli / HTTPURL

Function HTTPURL

pkg/cmd/issue/artifact/shared/shared.go:307–319  ·  view source on GitHub ↗

HTTPURL returns value with surrounding whitespace trimmed, and whether it is an http(s) URL: an absolute http or https URL with a host, in printable ASCII with no spaces. Artifact commands use this one check wherever they read or write a link. It is stricter than the server's because links are also

(value string)

Source from the content-addressed store, hash-verified

305// or write a link. It is stricter than the server's because links are also
306// stored in Internet Shortcut files, whose URL= line can't hold anything else.
307func HTTPURL(value string) (string, bool) {
308 trimmed := strings.TrimSpace(value)
309 for i := 0; i < len(trimmed); i++ {
310 if trimmed[i] <= ' ' || trimmed[i] > '~' {
311 return "", false
312 }
313 }
314 u, err := url.Parse(trimmed)
315 if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Hostname() == "" {
316 return "", false
317 }
318 return trimmed, true
319}

Callers 6

openInBrowserFunction · 0.92
readSourceFunction · 0.92
fileContentFunction · 0.92
newBodyFunction · 0.92
TestHTTPURLFunction · 0.85
ShortcutURLFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestHTTPURLFunction · 0.68