From e9fae413fdf8a7760c67399b8cb99ed9944fce40 Mon Sep 17 00:00:00 2001 From: john Date: Mon, 31 Dec 2018 09:31:57 -0800 Subject: options/path: fix url detection per RFC3986 --- options/path.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/options/path.c b/options/path.c index d2b74516e1..a8e39c3310 100644 --- a/options/path.c +++ b/options/path.c @@ -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; } -- cgit v1.2.3