diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-10-13 19:03:21 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-10-13 19:03:21 -0700 |
commit | 8b482c0ccca22857709e7f483f0079d7be7327f6 (patch) | |
tree | 7ba1c4084e848a3e0ca7b33e902d6e5d343b4c28 | |
parent | 522a54568e40f8b9110f9dde5664623bd5d039ce (diff) | |
parent | b33a1b9fe794df53b449ffdbba0b39ef9e1772bf (diff) | |
download | git-8b482c0ccca22857709e7f483f0079d7be7327f6.tar.gz |
Merge branch 'jc/is-url-simplify'
* jc/is-url-simplify:
url.c: simplify is_url()
-rw-r--r-- | url.c | 32 |
1 files changed, 6 insertions, 26 deletions
@@ -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) |