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)
| 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. |
| 307 | func 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 | } |
no outgoing calls