diff --git a/source/common/router/config_impl.cc b/source/common/router/config_impl.cc index b41cf84b1643a..5a8635f04e3d9 100644 --- a/source/common/router/config_impl.cc +++ b/source/common/router/config_impl.cc @@ -669,6 +669,10 @@ RouteEntryImplBase::RouteEntryImplBase(const VirtualHostImpl& vhost, "Specify only one of prefix_rewrite, regex_rewrite or path_rewrite_policy"); } + if (!route.route().prefix_rewrite().empty() && path_matcher_ != nullptr) { + throw EnvoyException("Cannot use prefix_rewrite with matcher extension"); + } + if (route.route().has_regex_rewrite()) { auto rewrite_spec = route.route().regex_rewrite(); regex_rewrite_ = Regex::Utility::parseRegex(rewrite_spec.pattern()); diff --git a/test/common/router/config_impl_test.cc b/test/common/router/config_impl_test.cc index 32b77cad6900b..fd52980f39f97 100644 --- a/test/common/router/config_impl_test.cc +++ b/test/common/router/config_impl_test.cc @@ -8840,6 +8840,30 @@ TEST_F(RouteConfigurationV2, TemplatePatternIsDisabledWhenNotSpecifiedInRouteAct EXPECT_TRUE(pattern_template_policy == nullptr); } +TEST_F(RouteConfigurationV2, RouteMatcherExtensionAndPrefixRewrite) { + const std::string yaml = R"EOF( +virtual_hosts: + - name: path_pattern + domains: ["*"] + routes: + - match: + path_match_policy: + name: envoy.path.match.uri_template.uri_template_matcher + typed_config: + "@type": type.googleapis.com/envoy.extensions.path.match.uri_template.v3.UriTemplateMatchConfig + path_template: "/bar/{country}/{hang}" + route: + cluster: some-cluster + prefix_rewrite: "!" + + )EOF"; + + factory_context_.cluster_manager_.initializeClusters({"some-cluster"}, {}); + EXPECT_THROW_WITH_MESSAGE( + TestConfigImpl config(parseRouteConfigurationFromYaml(yaml), factory_context_, true), + EnvoyException, "Cannot use prefix_rewrite with matcher extension"); +} + TEST_F(RouteConfigurationV2, TemplatePatternIsFilledFromConfigInRouteAction) { const std::string yaml = R"EOF( virtual_hosts: