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