| 102 | |
| 103 | |
| 104 | Try<string> Fetcher::basename(const string& uri) |
| 105 | { |
| 106 | // TODO(bernd-mesos): full URI parsing, then move this to stout. |
| 107 | // There is a bug (or is it a feature?) in the original fetcher |
| 108 | // code without caching that remains in effect here. URIs are |
| 109 | // treated like file paths, looking for occurrences of "/", |
| 110 | // but ignoring other separators that can show up |
| 111 | // (e.g. "?", "=" in HTTP URLs). |
| 112 | |
| 113 | if (uri.find_first_of('\\') != string::npos || |
| 114 | uri.find_first_of('\'') != string::npos || |
| 115 | uri.find_first_of('\0') != string::npos) { |
| 116 | return Error("Illegal characters in URI"); |
| 117 | } |
| 118 | |
| 119 | size_t index = uri.find("://"); |
| 120 | if (index != string::npos && 1 < index) { |
| 121 | // URI starts with protocol specifier, e.g., http://, https://, |
| 122 | // ftp://, ftps://, hdfs://, hftp://, s3://, s3n://. |
| 123 | |
| 124 | string path = uri.substr(index + 3); |
| 125 | if (!strings::contains(path, "/") || path.size() <= path.find('/') + 1) { |
| 126 | return Error("Malformed URI (missing path): " + uri); |
| 127 | } |
| 128 | |
| 129 | return path.substr(path.find_last_of('/') + 1); |
| 130 | } |
| 131 | return Path(uri).basename(); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | Try<Nothing> Fetcher::validateUri(const string& uri) |