refactor(测试跟踪): 禅道创建缺陷失败给出提示
--bug=1014318 --user=陈建星 【测试跟踪】缺陷管理新添加的自定义字段,输入为空保存会报错 https://www.tapd.cn/55049933/s/1189354
This commit is contained in:
parent
dff8015412
commit
d795144d61
|
@ -0,0 +1,74 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class UnicodeConvertUtils {
|
||||
|
||||
// 单个字符的正则表达式
|
||||
private static final String singlePattern = "[0-9|a-f|A-F]";
|
||||
// 4个字符的正则表达式
|
||||
private static final String pattern = singlePattern + singlePattern +
|
||||
singlePattern + singlePattern;
|
||||
|
||||
|
||||
/**
|
||||
* 把 \\u 开头的单字转成汉字,如 \\u6B65 -> 步
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static String ustartToCn(final String str) {
|
||||
StringBuilder sb = new StringBuilder().append("0x")
|
||||
.append(str.substring(2, 6));
|
||||
Integer codeInteger = Integer.decode(sb.toString());
|
||||
int code = codeInteger.intValue();
|
||||
char c = (char)code;
|
||||
return String.valueOf(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串是否以Unicode字符开头。约定Unicode字符以 \\u开头。
|
||||
* @param str 字符串
|
||||
* @return true表示以Unicode字符开头.
|
||||
*/
|
||||
private static boolean isStartWithUnicode(final String str) {
|
||||
if (null == str || str.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!str.startsWith("\\u")) {
|
||||
return false;
|
||||
}
|
||||
// \u6B65
|
||||
if (str.length() < 6) {
|
||||
return false;
|
||||
}
|
||||
String content = str.substring(2, 6);
|
||||
|
||||
boolean isMatch = Pattern.matches(pattern, content);
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串中,所有以 \\u 开头的UNICODE字符串,全部替换成汉字
|
||||
* @return
|
||||
*/
|
||||
public static String unicodeToCn(final String str) {
|
||||
// 用于构建新的字符串
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 从左向右扫描字符串。tmpStr是还没有被扫描的剩余字符串。
|
||||
// 下面有两个判断分支:
|
||||
// 1. 如果剩余字符串是Unicode字符开头,就把Unicode转换成汉字,加到StringBuilder中。然后跳过这个Unicode字符。
|
||||
// 2.反之, 如果剩余字符串不是Unicode字符开头,把普通字符加入StringBuilder,向右跳过1.
|
||||
int length = str.length();
|
||||
for (int i = 0; i < length;) {
|
||||
String tmpStr = str.substring(i);
|
||||
if (isStartWithUnicode(tmpStr)) { // 分支1
|
||||
sb.append(ustartToCn(tmpStr));
|
||||
i += 6;
|
||||
} else { // 分支2
|
||||
sb.append(str.substring(i, i + 1));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package io.metersphere.track.issue.client;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.UnicodeConvertUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.track.issue.domain.zentao.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -85,7 +85,11 @@ public abstract class ZentaoClient extends BaseClient {
|
|||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
AddIssueResponse addIssueResponse = (AddIssueResponse) getResultForObject(AddIssueResponse.class, response);
|
||||
return JSONObject.parseObject(addIssueResponse.getData(), AddIssueResponse.Issue.class);
|
||||
AddIssueResponse.Issue issue = JSONObject.parseObject(addIssueResponse.getData(), AddIssueResponse.Issue.class);
|
||||
if (issue == null) {
|
||||
MSException.throwException(UnicodeConvertUtils.unicodeToCn(response.getBody()));
|
||||
}
|
||||
return issue;
|
||||
}
|
||||
|
||||
public void updateIssue(String id, MultiValueMap<String, Object> paramMap) {
|
||||
|
|
Loading…
Reference in New Issue