Fix a backward compatibility bug.

To remain backward compatible, we only set port if it's a non-emptry
string.  But, we always store host.
pull/19488/head
Soheil Hassas Yeganeh 6 years ago
parent c9ec1a64ed
commit fedf7e373e
  1. 6
      src/core/lib/gprpp/host_port.cc
  2. 8
      test/core/gprpp/host_port_test.cc

@ -93,8 +93,12 @@ bool SplitHostPort(StringView name, UniquePtr<char>* host,
StringView port_view;
const bool ret = SplitHostPort(name, &host_view, &port_view);
if (ret) {
// We always set the host, but port is set only when it's non-empty,
// to remain backward compatible with the old split_host_port API.
*host = host_view.dup();
*port = port_view.dup();
if (!port_view.empty()) {
*port = port_view.dup();
}
}
return ret;
}

@ -68,10 +68,10 @@ static void split_host_port_expect(const char* name, const char* host,
}
static void test_split_host_port() {
split_host_port_expect("", "", "", true);
split_host_port_expect("[a:b]", "a:b", "", true);
split_host_port_expect("1.2.3.4", "1.2.3.4", "", true);
split_host_port_expect("a:b:c::", "a:b:c::", "", true);
split_host_port_expect("", "", nullptr, true);
split_host_port_expect("[a:b]", "a:b", nullptr, true);
split_host_port_expect("1.2.3.4", "1.2.3.4", nullptr, true);
split_host_port_expect("a:b:c::", "a:b:c::", nullptr, true);
split_host_port_expect("[a:b]:30", "a:b", "30", true);
split_host_port_expect("1.2.3.4:30", "1.2.3.4", "30", true);
split_host_port_expect(":30", "", "30", true);

Loading…
Cancel
Save