summaryrefslogtreecommitdiffstats
path: root/options/path.c
diff options
context:
space:
mode:
authorjohn <john.luke.greco@gmail.com>2018-12-31 09:31:57 -0800
committerJan Ekström <jeebjp@gmail.com>2019-04-05 20:48:24 +0300
commite9fae413fdf8a7760c67399b8cb99ed9944fce40 (patch)
tree1989455a875e4e7e026850cb71c56128120c54b3 /options/path.c
parent8b114e574abd08892612e21e784ea1872e1adf8c (diff)
downloadmpv-e9fae413fdf8a7760c67399b8cb99ed9944fce40.tar.bz2
mpv-e9fae413fdf8a7760c67399b8cb99ed9944fce40.tar.xz
options/path: fix url detection per RFC3986
Diffstat (limited to 'options/path.c')
-rw-r--r--options/path.c10
1 files 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;
}