mirror of https://github.com/mpv-player/mpv
path: better check for mp_is_url()
The previous check just searched for a "://" substring. This was quite bad, because "://" can be a valid part of a path. Later, I added special handling for filenames starting with "." and "/", so that you could reliably pass arbitrary filenames to mpv, no matter how messed up they were. Even though it doesn't really matter in practise anymore, this is still crap, so add a more reliable check instead.
This commit is contained in:
parent
3bb217d5e9
commit
191ac00af2
|
@ -231,7 +231,15 @@ bool mp_path_isdir(const char *path)
|
|||
// Return false if it's considered a normal local filesystem path.
|
||||
bool mp_is_url(bstr path)
|
||||
{
|
||||
// The URL check is a bit murky, but "/path" and "./path" are never URLs.
|
||||
return path.len && path.start[0] != '/' && path.start[0] != '.' &&
|
||||
bstr_find0(path, "://") >= 0;
|
||||
int proto = bstr_find0(path, "://");
|
||||
if (proto < 0)
|
||||
return false;
|
||||
// The protocol part must be alphanumeric, otherwise it's not an URL.
|
||||
for (int i = 0; i < proto; i++) {
|
||||
unsigned char c = path.start[i];
|
||||
if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') &&
|
||||
!(c >= '0' && c <= '9') && c != '_')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue