diff options
author | wm4 <wm4@nowhere> | 2013-09-04 16:28:02 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-09-04 16:28:02 +0200 |
commit | 191ac00af277f0d798716e2e8d0419656c011b52 (patch) | |
tree | 452499a00b3a7d59e102df4c407323e76de04d0c | |
parent | 3bb217d5e9fda241693c7f3c6a4046c845d8d5a8 (diff) | |
download | mpv-191ac00af277f0d798716e2e8d0419656c011b52.tar.bz2 mpv-191ac00af277f0d798716e2e8d0419656c011b52.tar.xz |
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.
-rw-r--r-- | mpvcore/path.c | 14 |
1 files 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; } |