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)
| 473 | // rather than a network host: a file:// URL, a POSIX absolute/relative/home |
| 474 | // path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share). |
| 475 | func isLocalRemote(s string) bool { |
| 476 | switch { |
| 477 | case strings.HasPrefix(s, "file://"): |
| 478 | return true |
| 479 | case strings.HasPrefix(s, "/"), strings.HasPrefix(s, "~"): |
| 480 | return true |
| 481 | case strings.HasPrefix(s, "./"), strings.HasPrefix(s, "../"), s == ".", s == "..": |
| 482 | return true |
| 483 | case strings.HasPrefix(s, `\\`): // UNC \\server\share |
| 484 | return true |
| 485 | } |
| 486 | // Windows drive path: X:\ or X:/. Require a separator after the colon so a |
| 487 | // single-letter scp host ("c:path") is not misread — real hosts have a dot. |
| 488 | if len(s) >= 3 && isASCIILetter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') { |
| 489 | return true |
| 490 | } |
| 491 | return false |
| 492 | } |
| 493 | |
| 494 | func isASCIILetter(b byte) bool { |
| 495 | return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') |
no test coverage detected