diff --git a/src/core/ext/filters/client_channel/xds/xds_api.cc b/src/core/ext/filters/client_channel/xds/xds_api.cc index 4cf5d8c26a2..3898fe4d5f1 100644 --- a/src/core/ext/filters/client_channel/xds/xds_api.cc +++ b/src/core/ext/filters/client_channel/xds/xds_api.cc @@ -1022,8 +1022,9 @@ grpc_error* RouteConfigParse( "No prefix field found in RouteMatch."); } const upb_strview prefix = envoy_api_v2_route_RouteMatch_prefix(match); - if (!upb_strview_eql(prefix, upb_strview_makez(""))) { - return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Prefix is not empty string."); + if (!upb_strview_eql(prefix, upb_strview_makez("")) && + !upb_strview_eql(prefix, upb_strview_makez("/"))) { + return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Prefix is not \"\" or \"/\"."); } if (!envoy_api_v2_route_Route_has_route(route)) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index 809ee59ee3d..7c03070190f 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -1799,6 +1799,26 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) { EXPECT_EQ(0, std::get<1>(counts)); } +TEST_P(XdsResolverOnlyTest, DefaultRouteSpecifiesSlashPrefix) { + RouteConfiguration route_config = + balancers_[0]->ads_service()->default_route_config(); + route_config.mutable_virtual_hosts(0) + ->mutable_routes(0) + ->mutable_match() + ->set_prefix("/"); + balancers_[0]->ads_service()->SetLdsResource( + AdsServiceImpl::BuildListener(route_config), kDefaultResourceName); + SetNextResolution({}); + SetNextResolutionForLbChannelAllBalancers(); + AdsServiceImpl::EdsResourceArgs args({ + {"locality0", GetBackendPorts()}, + }); + balancers_[0]->ads_service()->SetEdsResource( + AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName); + // We need to wait for all backends to come online. + WaitForAllBackends(); +} + class XdsResolverLoadReportingOnlyTest : public XdsEnd2endTest { public: XdsResolverLoadReportingOnlyTest() : XdsEnd2endTest(4, 1, 3) {}