X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=input.cpp;h=f5d8d5ef19ff8dced7f5d75a73b5a724b2942a82;hp=0ee7d1ce918af18a9999a414cc9014a97ae07f7d;hb=1dfa45f9af3f885a50d2bef384ea89b0a4cf17c5;hpb=70c47a998c5aa2eb536c3c8f71f3178cd217a14d diff --git a/input.cpp b/input.cpp index 0ee7d1c..f5d8d5e 100644 --- a/input.cpp +++ b/input.cpp @@ -37,8 +37,30 @@ bool parse_url(const string &url, string *protocol, string *user, string *host, *protocol = string(url.begin(), url.begin() + split); string rest = string(url.begin() + split + 3, url.end()); - split = rest.find_first_of(":/"); - if (split == string::npos) { + + // Split at the first slash, or the first colon that's not within []. + bool within_brackets = false; + for (split = 0; split < rest.size(); ++split) { + if (rest[split] == '[') { + if (within_brackets) { + // Can't nest brackets. + return false; + } + within_brackets = true; + } else if (rest[split] == ']') { + if (!within_brackets) { + // ] without matching [. + return false; + } + within_brackets = false; + } else if (rest[split] == '/') { + break; + } else if (rest[split] == ':' && !within_brackets) { + break; + } + } + + if (split == rest.size()) { // http://foo split_user_host(rest, user, host); *port = *protocol;