isLocalRemote reports whether a remote URL points at the local filesystem rather than a network host: a file:// URL, a POSIX absolute/relative/home path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share).
(s string)
| 491 | // rather than a network host: a file:// URL, a POSIX absolute/relative/home |
| 492 | // path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share). |
| 493 | func isLocalRemote(s string) bool { |
| 494 | switch { |
| 495 | case strings.HasPrefix(s, "file://"): |
| 496 | return true |
| 497 | case strings.HasPrefix(s, "/"), strings.HasPrefix(s, "~"): |
| 498 | return true |
| 499 | case strings.HasPrefix(s, "./"), strings.HasPrefix(s, "../"), s == ".", s == "..": |
| 500 | return true |
| 501 | case strings.HasPrefix(s, `\\`): // UNC \\server\share |
| 502 | return true |
| 503 | } |
| 504 | // Windows drive path: X:\ or X:/. Require a separator after the colon so a |
| 505 | // single-letter scp host ("c:path") is not misread — real hosts have a dot. |
| 506 | if len(s) >= 3 && isASCIILetter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') { |
| 507 | return true |
| 508 | } |
| 509 | return false |
| 510 | } |
| 511 | |
| 512 | func isASCIILetter(b byte) bool { |
| 513 | return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') |
no test coverage detected