我发现了一个奇怪的问题,即 urlencoding 的行为不一致。
更新
Spring MVC 4.3 和 5.1 版本之间存在差异:
// FAIL in MVC 4.x
@Test
public void test2() {
rt.getForObject("http://localhost/expr={expr}", String.class, "x/y");
Assert.assertEquals("http://localhost/expr=x%2Fy", savedUri.toString());
}
// FAIL in MVC 4 or 5
@Test
public void test3() {
rt.getForObject("http://localhost/expr={expr}", String.class, "x+y");
Assert.assertEquals("http://localhost/expr=x%2By", savedUri.toString());
}
// ok in MVC 4.x, FAIL in MVC 5
@Test
public void test4() {
rt.getForObject("http://localhost/expr={expr}", String.class, "x+y");
Assert.assertEquals("http://localhost/expr=x+y", savedUri.toString());
}
这可能是 Spring MVC 更大重构的一部分,因为它也出现在一个完全不同的地方
问题详情
以下独立测试最能说明我的问题。不要被ClientHttpRequestFactory- 重要的部分是最后 2 种测试方法所吓倒。
发生了什么:
除法符号/正确编码为%2F- test2() 通过
添加符号+未编码为 a %2B- 它仍然存在+并且 test3() 失败
应该发生什么:
test3() 应该通过。+应编码为 %2B,因为它+是 URL 中的特殊字符,并且被许多服务器端 Web 框架解释为空白。
这是怎么回事,是否有通用修复程序?
慕标琳琳
浮云间
随时随地看视频慕课网APP
相关分类