(s string)
| 183 | } |
| 184 | |
| 185 | func parseUNCPath(s string) (drive, p string, ok bool) { |
| 186 | // UNC paths use backslashes but we're using forward slashes |
| 187 | // so also enforce that here. |
| 188 | // |
| 189 | // In reality, this should have been enforced much earlier |
| 190 | // than here since backslashes aren't allowed in URLs, but |
| 191 | // we're going to code defensively here. |
| 192 | s = filepath.ToSlash(s) |
| 193 | |
| 194 | const uncPrefix = "//./" |
| 195 | if !strings.HasPrefix(s, uncPrefix) { |
| 196 | // Not a UNC path. |
| 197 | return "", "", false |
| 198 | } |
| 199 | s = s[len(uncPrefix):] |
| 200 | |
| 201 | parts := strings.SplitN(s, "/", 2) |
| 202 | if len(parts) != 2 { |
| 203 | // Not enough components. |
| 204 | return "", "", false |
| 205 | } |
| 206 | |
| 207 | drive, ok = splitWindowsDrive(parts[0]) |
| 208 | if !ok { |
| 209 | // Not a windows drive. |
| 210 | return "", "", false |
| 211 | } |
| 212 | return drive, "/" + parts[1], true |
| 213 | } |
| 214 | |
| 215 | // splitWindowsDrive checks if the string references a windows |
| 216 | // drive (such as c:) and returns the drive letter if it is. |
no test coverage detected
searching dependent graphs…