fix(接口测试): 修复mock请求中带中文时,匹配失败的缺陷
--bug=1041236 --user=王孝刚 【接口测试】Mock-Mock规则设置为Query参数值长度等于5,请求Mock地址时,Query参数传入长度等于5的中文字符串,Mock匹配失败 https://www.tapd.cn/55049933/s/1521289
This commit is contained in:
parent
ceb6e5b339
commit
793637536c
|
@ -13,9 +13,9 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -80,12 +80,13 @@ public class MockServerUtils {
|
|||
}
|
||||
}
|
||||
String queryString = request.getQueryString();
|
||||
|
||||
if (StringUtils.isNotEmpty(queryString)) {
|
||||
String[] queryParamArr = queryString.split("&");
|
||||
for (String queryParam : queryParamArr) {
|
||||
String[] queryParamKV = queryParam.split("=");
|
||||
if (queryParamKV.length == 2) {
|
||||
queryParamsMap.put(queryParamKV[0], queryParamKV[1]);
|
||||
queryParamsMap.put(queryParamKV[0], URLDecoder.decode(queryParamKV[1], StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,28 +160,13 @@ public class MockServerUtils {
|
|||
if (sendParamArr.length > i) {
|
||||
value = sendParamArr[i];
|
||||
}
|
||||
restParams.put(param, value);
|
||||
restParams.put(param, URLDecoder.decode(value, StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
return restParams;
|
||||
}
|
||||
|
||||
private static String getRequestStr(HttpServletRequest request) {
|
||||
String inputLine;
|
||||
// 接收到的数据
|
||||
StringBuilder receiveData = new StringBuilder();
|
||||
try (BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||
request.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
receiveData.append(inputLine);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
|
||||
return receiveData.toString();
|
||||
}
|
||||
|
||||
public static String getUrlSuffix(String mockUrlInfo, HttpServletRequest request) {
|
||||
String requestUri = request.getRequestURI();
|
||||
String[] urlParamArr = requestUri.split(mockUrlInfo);
|
||||
|
|
Loading…
Reference in New Issue