X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=url.c;h=e4262a0d7a9ef71924b117f4cbf9fe12d0239f0d;hb=d2843da029d10cdc2b335c19b77c14ae18a09f5d;hp=3e06fd34c46a00b41f4843ea87a151314ce0789c;hpb=e7734c6c9b04d78e970b8de4765cdebd984ec6e6;p=git.git diff --git a/url.c b/url.c index 3e06fd34c..e4262a0d7 100644 --- a/url.c +++ b/url.c @@ -18,35 +18,15 @@ int is_urlschemechar(int first_flag, int ch) int is_url(const char *url) { - const char *url2, *first_slash; - - if (!url) - return 0; - url2 = url; - first_slash = strchr(url, '/'); - - /* Input with no slash at all or slash first can't be URL. */ - if (!first_slash || first_slash == url) - return 0; - /* Character before must be : and next must be /. */ - if (first_slash[-1] != ':' || first_slash[1] != '/') + /* Is "scheme" part reasonable? */ + if (!url || !is_urlschemechar(1, *url++)) return 0; - /* There must be something before the :// */ - if (first_slash == url + 1) - return 0; - /* - * Check all characters up to first slash - 1. Only alphanum - * is allowed. - */ - url2 = url; - while (url2 < first_slash - 1) { - if (!is_urlschemechar(url2 == url, (unsigned char)*url2)) + while (*url && *url != ':') { + if (!is_urlschemechar(0, *url++)) return 0; - url2++; } - - /* Valid enough. */ - return 1; + /* We've seen "scheme"; we want colon-slash-slash */ + return (url[0] == ':' && url[1] == '/' && url[2] == '/'); } static int url_decode_char(const char *q)