Update uri_parser

pull/2882/head
Hongwei Wang 9 years ago
parent a3780a8102
commit f0e9fecbe0
  1. 2
      src/core/client_config/uri_parser.c
  2. 17
      test/core/client_config/uri_parser_test.c

@ -98,7 +98,7 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) {
if (uri_text[scheme_end + 1] == '/' && uri_text[scheme_end + 2] == '/') { if (uri_text[scheme_end + 1] == '/' && uri_text[scheme_end + 2] == '/') {
authority_begin = scheme_end + 3; authority_begin = scheme_end + 3;
for (i = authority_begin; uri_text[i] != 0; i++) { for (i = authority_begin; uri_text[i] != 0 && authority_end == -1; i++) {
if (uri_text[i] == '/') { if (uri_text[i] == '/') {
authority_end = i; authority_end = i;
} }

@ -44,30 +44,27 @@ static void test_succeeds(const char *uri_text, const char *scheme,
grpc_uri *uri = grpc_uri_parse(uri_text, 0); grpc_uri *uri = grpc_uri_parse(uri_text, 0);
GPR_ASSERT(uri); GPR_ASSERT(uri);
GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); GPR_ASSERT(0 == strcmp(scheme, uri->scheme));
gpr_log(GPR_INFO, uri->scheme);
gpr_log(GPR_INFO, uri->authority);
gpr_log(GPR_INFO, uri->path);
GPR_ASSERT(0 == strcmp(authority, uri->authority)); GPR_ASSERT(0 == strcmp(authority, uri->authority));
GPR_ASSERT(0 == strcmp(path, uri->path)); GPR_ASSERT(0 == strcmp(path, uri->path));
grpc_uri_destroy(uri); grpc_uri_destroy(uri);
} }
/*static void test_fails(const char *uri_text) { static void test_fails(const char *uri_text) {
GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0));
}*/ }
int main(int argc, char **argv) { int main(int argc, char **argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
/*test_succeeds("http://www.google.com", "http", "www.google.com", ""); test_succeeds("http://www.google.com", "http", "www.google.com", "");
test_succeeds("dns:///foo", "dns", "", "/foo");*/ test_succeeds("dns:///foo", "dns", "", "/foo");
test_succeeds("zookeeper://127.0.0.1:2181/foo/1", "zookeeper", "127.0.0.1:2181", "/foo/1"); test_succeeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper", "127.0.0.1:2181", "/foo/bar");
/*test_succeeds("http://www.google.com:90", "http", "www.google.com:90", ""); test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "");
test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom"); test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom");
test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom"); test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom");
test_fails("xyz"); test_fails("xyz");
test_fails("http://www.google.com?why-are-you-using-queries"); test_fails("http://www.google.com?why-are-you-using-queries");
test_fails("dns:foo.com#fragments-arent-supported-here"); test_fails("dns:foo.com#fragments-arent-supported-here");
test_fails("http:?huh"); test_fails("http:?huh");
test_fails("unix:#yeah-right");*/ test_fails("unix:#yeah-right");
return 0; return 0;
} }

Loading…
Cancel
Save