From 191ac00af277f0d798716e2e8d0419656c011b52 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 4 Sep 2013 16:28:02 +0200 Subject: [PATCH] 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. --- mpvcore/path.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mpvcore/path.c b/mpvcore/path.c index 5893284b5e..9de6291975 100644 --- a/mpvcore/path.c +++ b/mpvcore/path.c @@ -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; }