1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:42:17 +00:00

options/path: fix url detection per RFC3986

This commit is contained in:
john 2018-12-31 09:31:57 -08:00 committed by Jan Ekström
parent 8b114e574a
commit e9fae413fd

View File

@ -37,6 +37,7 @@
#include "mpv_talloc.h"
#include "osdep/io.h"
#include "osdep/path.h"
#include "misc/ctype.h"
// In order of decreasing priority: the first has highest priority.
static const mp_get_platform_path_cb path_resolvers[] = {
@ -323,12 +324,15 @@ bool mp_is_url(bstr path)
int proto = bstr_find0(path, "://");
if (proto < 1)
return false;
// The protocol part must be alphanumeric, otherwise it's not an URL.
// Per RFC3986, the first character of the protocol must be alphabetic.
// The rest must be alphanumeric plus -, + and .
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 != '_')
if ((i == 0 && !mp_isalpha(c)) ||
(!mp_isalnum(c) && c != '.' && c != '-' && c != '+'))
{
return false;
}
}
return true;
}