feat(app): Tomcat relaxedQueryChars 放开 []{}| (amis 多选 picker 括号参数)
amis 多选 picker 发 value[0]=&value[1]= 等未编码方括号 query → Tomcat 默认 400(在到达 controller 前)。配 relaxedQueryChars=[]{}| 放行,使 picker loadOptions 多值解析可达。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
package com.eip4.platform.app.config;
|
||||||
|
|
||||||
|
import org.apache.catalina.connector.Connector;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||||
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 放宽 Tomcat 查询串允许字符,接纳未编码的方括号 {@code [ ]}(及 {@code { } |})。
|
||||||
|
*
|
||||||
|
* <p><b>动机(amis picker 多选加载已存值显名)</b>:amis 用 {@code qs(arrayFormat='indices',
|
||||||
|
* encodeValuesOnly=true)} 序列化数组查询参数——只编码值、不编码键,故多选 picker 加载已存值时
|
||||||
|
* 原生发出的 loadOptions 请求形如 {@code /api/picker/{id}/list?value[0]=v1&value[1]=v2&op=loadOptions},
|
||||||
|
* query 串里带<b>未编码</b>的 {@code [ ]}。Tomcat 默认按 RFC 3986 严格校验 query 字符,遇未编码
|
||||||
|
* {@code [ ]} 直接回 400(在进 Spring MVC 之前,控制器无从处理)——表现为多选 picker 显裸 id、
|
||||||
|
* 控制台「ajax 动作执行失败」。放宽这几个字符后,{@code MultiValueMap} 即可绑定 {@code value[n]},
|
||||||
|
* {@link com.eip4.platform.metadata.web.PickerController} 的 {@code op=loadOptions} 分支正常解析显示名。
|
||||||
|
*
|
||||||
|
* <p>这是 amis + Spring Boot 的标准兼容设置:amis 各类 CRUD 的数组型过滤/排序参数普遍走 indices
|
||||||
|
* 方括号形态,本放宽对全站 amis 数组查询通用生效(非仅 picker)。{@code [ ]} 仅出现在 query 串、
|
||||||
|
* 经引擎参数化/白名单消费,放宽字符集不削弱既有注入防护。
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class TomcatRelaxedQueryConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> relaxedQueryCharsCustomizer() {
|
||||||
|
return factory -> factory.addConnectorCustomizers(this::relaxConnector);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void relaxConnector(Connector connector) {
|
||||||
|
// amis qs indices 数组键用 [ ];{ } | 一并放宽以覆盖 amis 其它查询编码场景。
|
||||||
|
connector.setProperty("relaxedQueryChars", "[]{}|");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user