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)
| 552 | // rather than a network host: a file:// URL, a POSIX absolute/relative/home |
| 553 | // path, a Windows drive path (X:\ or X:/), or a UNC share (\\server\share). |
| 554 | func isLocalRemote(s string) bool { |
| 555 | switch { |
| 556 | case strings.HasPrefix(s, "file://"): |
| 557 | return true |
| 558 | case strings.HasPrefix(s, "/"), strings.HasPrefix(s, "~"): |
| 559 | return true |
| 560 | case strings.HasPrefix(s, "./"), strings.HasPrefix(s, "../"), s == ".", s == "..": |
| 561 | return true |
| 562 | case strings.HasPrefix(s, `\\`): // UNC \\server\share |
| 563 | return true |
| 564 | } |
| 565 | // Windows drive path: X:\ or X:/. Require a separator after the colon so a |
| 566 | // single-letter scp host ("c:path") is not misread — real hosts have a dot. |
| 567 | if len(s) >= 3 && isASCIILetter(s[0]) && s[1] == ':' && (s[2] == '\\' || s[2] == '/') { |
| 568 | return true |
| 569 | } |
| 570 | return false |
| 571 | } |
| 572 | |
| 573 | func isASCIILetter(b byte) bool { |
| 574 | return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') |
no test coverage detected