mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复JSONStrFormatter:format函数对于转义符号处理逻辑错误问题
This commit is contained in:
parent
60746e8a8f
commit
f245a721f6
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.23(2023-09-25)
|
||||
# 5.8.23(2023-09-28)
|
||||
|
||||
### 🐣新特性
|
||||
* 【json 】 改进TemporalAccessorSerializer支持dayOfMonth和month枚举名(issue#I82AM8@Gitee)
|
||||
@ -12,6 +12,7 @@
|
||||
### 🐞Bug修复
|
||||
* 【cron 】 修复Cron表达式range解析错误问题(issue#I82CSH@Gitee)
|
||||
* 【core 】 修复VersionComparator在极端数据排序时候违反了自反性问题(issue#I81N3H@Gitee)
|
||||
* 【json 】 修复JSONStrFormatter:format函数对于转义符号处理逻辑错误问题(issue#I84V6I@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.22(2023-09-13)
|
||||
|
@ -42,10 +42,12 @@ public class JSONStrFormatter {
|
||||
if (null == wrapChar) {
|
||||
//字符串模式开始
|
||||
wrapChar = key;
|
||||
} else if (isEscapeMode) {
|
||||
//在字符串模式下的转义
|
||||
isEscapeMode = false;
|
||||
} else if (wrapChar.equals(key)) {
|
||||
if (isEscapeMode) {
|
||||
//字符串模式下,遇到结束符号,也同时结束转义
|
||||
isEscapeMode = false;
|
||||
}
|
||||
|
||||
//字符串包装结束
|
||||
wrapChar = null;
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IssueI84V6ITest {
|
||||
@Test
|
||||
public void formatTest() {
|
||||
final String a1 = "{'x':'\\n','y':','}";
|
||||
final String formatJsonStr = JSONUtil.formatJsonStr(a1);
|
||||
// Console.log(formatJsonStr);
|
||||
Assert.assertEquals(
|
||||
"{\n" +
|
||||
" 'x': '\\n',\n" +
|
||||
" 'y': ','\n" +
|
||||
"}", formatJsonStr);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user