Browse Source

fix:occur a 400 error request when openapi key's parameter contain "a[0]" (#4424)

* fix:occur a 400 error request when openapi key's parameter contain "a[0]"(#4422)

* update CHANGES.md
CalebZYC 2 years ago
parent
commit
7d25d55cf0

+ 1 - 0
CHANGES.md

@@ -9,5 +9,6 @@ Apollo 2.1.0
 * [feat(apollo-client): the spi of config service load balancer client](https://github.com/apolloconfig/apollo/pull/4394)
 * [add cat-client as optional dependency](https://github.com/apolloconfig/apollo/pull/4414)
 * [refactor Functions class with lambda](https://github.com/apolloconfig/apollo/pull/4419)
+* [fix:occur a 400 error request when openapi key's parameter contain "a[0]"](https://github.com/apolloconfig/apollo/pull/4424)
 ------------------
 All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/11?closed=1)

+ 17 - 0
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/PortalOpenApiConfig.java

@@ -16,13 +16,30 @@
  */
 package com.ctrip.framework.apollo.openapi;
 
+import com.ctrip.framework.apollo.common.controller.WebMvcConfig;
+
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
 
 @EnableAutoConfiguration
 @Configuration
 @ComponentScan(basePackageClasses = PortalOpenApiConfig.class)
 public class PortalOpenApiConfig {
 
+	@Component
+	static class PortalWebMvcConfig extends WebMvcConfig {
+		@Override
+		public void customize(TomcatServletWebServerFactory factory) {
+			final String relaxedChars = "<>[\\]^`{|}";
+			final String tomcatRelaxedpathcharsProperty = "relaxedPathChars";
+			final String tomcatRelaxedquerycharsProperty = "relaxedQueryChars";
+			factory.addConnectorCustomizers(connector -> {
+				connector.setProperty(tomcatRelaxedpathcharsProperty, relaxedChars);
+				connector.setProperty(tomcatRelaxedquerycharsProperty, relaxedChars);
+			});
+		}
+	}
 }