Branch Coverage

src/panda/uri/URI.cc
Criterion Covered Total %
branch 176 298 59.0


line true false branch
18 0 0 register_scheme(scheme, &typeid(URI), [](const URI& u)->URI*{ return new URI(u); }, default_port, secure);
0 0 register_scheme(scheme, &typeid(URI), [](const URI& u)->URI*{ return new URI(u); }, default_port, secure);
22 117 0 if (scheme_map.find(scheme) != scheme_map.end())
0 117 if (scheme_map.find(scheme) != scheme_map.end())
23 0 0 throw std::invalid_argument("URI::register_scheme: scheme '" + scheme + "' has been already registered");
0 0 throw std::invalid_argument("URI::register_scheme: scheme '" + scheme + "' has been already registered");
0 0 throw std::invalid_argument("URI::register_scheme: scheme '" + scheme + "' has been already registered");
0 0 throw std::invalid_argument("URI::register_scheme: scheme '" + scheme + "' has been already registered");
32 117 0 schemas.push_back(&inf);
37 13 0 URI::register_scheme("http", &typeid(URI::http), [](const URI& u)->URI*{ return new URI::http(u); }, 80 );
11 0 URI::register_scheme("http", &typeid(URI::http), [](const URI& u)->URI*{ return new URI::http(u); }, 80 );
38 13 0 URI::register_scheme("https", &typeid(URI::https), [](const URI& u)->URI*{ return new URI::https(u); }, 443, true);
1 0 URI::register_scheme("https", &typeid(URI::https), [](const URI& u)->URI*{ return new URI::https(u); }, 443, true);
39 13 0 URI::register_scheme("ws", &typeid(URI::ws), [](const URI& u)->URI*{ return new URI::ws(u); }, 80 );
1 0 URI::register_scheme("ws", &typeid(URI::ws), [](const URI& u)->URI*{ return new URI::ws(u); }, 80 );
40 13 0 URI::register_scheme("wss", &typeid(URI::wss), [](const URI& u)->URI*{ return new URI::wss(u); }, 443, true);
1 0 URI::register_scheme("wss", &typeid(URI::wss), [](const URI& u)->URI*{ return new URI::wss(u); }, 443, true);
41 13 0 URI::register_scheme("ftp", &typeid(URI::ftp), [](const URI& u)->URI*{ return new URI::ftp(u); }, 21 );
1 0 URI::register_scheme("ftp", &typeid(URI::ftp), [](const URI& u)->URI*{ return new URI::ftp(u); }, 21 );
42 13 0 URI::register_scheme("socks5", &typeid(URI::socks), [](const URI& u)->URI*{ return new URI::socks(u); }, 1080 );
1 0 URI::register_scheme("socks5", &typeid(URI::socks), [](const URI& u)->URI*{ return new URI::socks(u); }, 1080 );
43 13 0 URI::register_scheme("ssh", &typeid(URI::ssh), [](const URI& u)->URI*{ return new URI::ssh(u); }, 22, true);
1 0 URI::register_scheme("ssh", &typeid(URI::ssh), [](const URI& u)->URI*{ return new URI::ssh(u); }, 22, true);
44 13 0 URI::register_scheme("telnet", &typeid(URI::telnet), [](const URI& u)->URI*{ return new URI::telnet(u); }, 23 );
1 0 URI::register_scheme("telnet", &typeid(URI::telnet), [](const URI& u)->URI*{ return new URI::telnet(u); }, 23 );
45 13 0 URI::register_scheme("sftp", &typeid(URI::sftp), [](const URI& u)->URI*{ return new URI::sftp(u); }, 22, true);
1 0 URI::register_scheme("sftp", &typeid(URI::sftp), [](const URI& u)->URI*{ return new URI::sftp(u); }, 22, true);
47 13 0 http_si = &scheme_map.find("http")->second;
48 13 0 https_si = &scheme_map.find("https")->second;
60 3 6 if (!_scheme.length()) {
62 1 2 if (delim == string::npos) {
76 16 2 for (; i < plen; ++i) {
78 14 2 if (c >= '0' && c <= '9') {
12 2 if (c >= '0' && c <= '9') {
83 2 2 if (c != '/') { _port = 0; return; }
87 2 2 if (!ok) return;
96 334 2 if (!relative) approx_len += (_scheme.length()+3) + (_user_info.length()*3 + 1) + (_host.length()*3 + 6);
99 334 2 if (!relative) {
100 257 77 if (_scheme.length()) {
101 257 0 str += _scheme;
102 192 65 if (_host.length()) str += "://";
192 0 if (_host.length()) str += "://";
103 65 0 else str += ':';
105 52 25 else if (_host.length()) str += "//";
52 0 else if (_host.length()) str += "//";
107 244 90 if (_host.length()) {
108 50 194 if (_user_info.length()) {
109 50 0 _encode_uri_component_append(_user_info, str, URIComponent::user_info);
110 50 0 str += '@';
114 35 209 if (chost.front() == '[' && chost.back() == ']') str += _host;
35 0 if (chost.front() == '[' && chost.back() == ']') str += _host;
35 209 if (chost.front() == '[' && chost.back() == ']') str += _host;
35 0 if (chost.front() == '[' && chost.back() == ']') str += _host;
115 209 0 else _encode_uri_component_append(_host, str, URIComponent::host);
117 65 179 if (_port) {
118 65 0 str += ':';
119 65 0 str += string::from_number(_port);
65 0 str += string::from_number(_port);
124 185 151 if (_path.length()) str += _path;
185 0 if (_path.length()) str += _path;
125 2 149 else if (relative) str += '/'; // relative path MUST NOT be empty
2 0 else if (relative) str += '/'; // relative path MUST NOT be empty
127 102 234 if (_qstr.length()) {
128 102 0 str += '?';
129 102 0 str += _qstr; // as is, because already encoded either by raw_query setter or by compile_query
132 98 238 if (_fragment.length()) {
133 98 0 str += '#';
134 98 0 str += _fragment;
146 1 7 const char delim = _flags & Flags::query_param_semicolon ? ';' : '&';
151 7 1 if (len) for (int i = 0; i <= len; ++i) {
92 7 if (len) for (int i = 0; i <= len; ++i) {
152 85 7 char c = (i == len) ? delim : str[i];
153 16 76 if (c == '=' && mode == PARSE_MODE_KEY) {
16 0 if (c == '=' && mode == PARSE_MODE_KEY) {
158 3 73 else if (c == '%') {
161 17 56 else if (c == delim) {
162 1 16 if (mode == PARSE_MODE_KEY) {
167 3 14 if (has_pct) {
170 3 0 if (klen > 0) decode_uri_component(string_view(str+key_start, klen), key);
3 0 if (klen > 0) decode_uri_component(string_view(str+key_start, klen), key);
173 3 0 if (vlen > 0) decode_uri_component(string_view(str+val_start, vlen), value);
3 0 if (vlen > 0) decode_uri_component(string_view(str+val_start, vlen), value);
176 3 0 _query.emplace(key, value);
178 14 0 _query.emplace(_qstr.substr(key_start, key_end - key_start), _qstr.substr(val_start, i - val_start));
14 0 _query.emplace(_qstr.substr(key_start, key_end - key_start), _qstr.substr(val_start, i - val_start));
191 0 6 const char delim = _flags & Flags::query_param_semicolon ? ';' : '&';
196 16 6 for (auto it = begin; it != end; ++it) bufsize += (it->first.length() + it->second.length())*3 + 2;
197 6 0 if (bufsize) --bufsize;
199 6 0 _qstr.reserve(bufsize);
201 6 0 char* bufp = _qstr.buf();
203 16 6 for (auto it = begin; it != end; ++it) {
204 10 6 if (it != begin) *ptr++ = delim;
205 16 0 ptr += encode_uri_component(it->first, ptr);
207 16 0 ptr += encode_uri_component(it->second, ptr);
215 0 0 sync_query();
217 0 0 for (auto it = addquery.cbegin(); it != end; ++it) _query.emplace(it->first, it->second);
0 0 for (auto it = addquery.cbegin(); it != end; ++it) _query.emplace(it->first, it->second);
223 1 4 if (!plen) return std::vector();
225 4 0 ret.reserve(7);
228 30 4 for (size_t i = 0; i < plen; ++i) {
229 22 8 if (p[i] != '/') continue;
230 4 4 if (i == start) { start++; continue; }
231 4 0 ret.push_back(decode_uri_component(string_view(p+start, i-start)));
4 0 ret.push_back(decode_uri_component(string_view(p+start, i-start)));
234 2 2 if (p[plen-1] != '/') ret.push_back(string(p+start, plen-start));
2 0 if (p[plen-1] != '/') ret.push_back(string(p+start, plen-start));
2 0 if (p[plen-1] != '/') ret.push_back(string(p+start, plen-start));
253 25 128 if (!_scheme) {
259 104 24 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
104 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 18 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 42 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 42 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 42 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
104 24 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
86 42 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
0 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
0 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
0 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
0 0 if (len >= 4 && (_scheme[0]|0x20) == 'h' && (_scheme[1]|0x20) == 't' && (_scheme[2]|0x20) == 't' && (_scheme[3]|0x20) == 'p') {
260 58 28 if (len == 4) {
262 58 0 _scheme = "http";
264 28 0 else if (len == 5 && (_scheme[4]|0x20) == 's') {
28 0 else if (len == 5 && (_scheme[4]|0x20) == 's') {
28 0 else if (len == 5 && (_scheme[4]|0x20) == 's') {
28 0 else if (len == 5 && (_scheme[4]|0x20) == 's') {
28 0 else if (len == 5 && (_scheme[4]|0x20) == 's') {
0 0 else if (len == 5 && (_scheme[4]|0x20) == 's') {
266 28 0 _scheme = "https";
273 42 0 char* p = _scheme.buf();
275 160 42 for (;p != end; ++p) *p = tolower(*p);
277 42 0 auto it = scheme_map.find(_scheme);
278 18 24 if (it == scheme_map.cend()) scheme_info = NULL;
283 0 0 auto it = scheme_ti_map.find(ti);
284 0 0 return it == scheme_ti_map.end() ? nullptr : it->second;
289 0 0 if (delim == string::npos) return _user_info;
295 0 0 if (delim == string::npos) _user_info = user;
301 0 0 if (delim == string::npos) return string();
307 0 0 if (delim == string::npos) {
315 0 0 string tmp = uri.to_string();
316 0 0 return os.write(tmp.data(), tmp.length());
319 13 0 }}
13 0 }}