mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
🐞修复JSONStrFormatter:format函数对于转义符号处理逻辑错误问题
This commit is contained in:
parent
997f2af8cd
commit
0c3f91bad3
@ -22,7 +22,8 @@ import java.util.function.Predicate;
|
||||
* 包装 {@link Iterator}并根据{@link Predicate}定义,过滤元素输出<br>
|
||||
* 类实现来自Apache Commons Collection
|
||||
*
|
||||
* @author mina commons, looly
|
||||
* @param <E> 元素类型
|
||||
* @author Apahce-commons, looly
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public class FilterIter<E> implements Iterator<E> {
|
||||
|
@ -24,7 +24,7 @@ import java.util.NoSuchElementException;
|
||||
* <p>
|
||||
* 此 iterator 不支持 {@link #remove()} 方法。
|
||||
*
|
||||
* @author mina commons,looly
|
||||
* @author Apache-commons,looly
|
||||
* @see NodeList
|
||||
* @since 5.8.0
|
||||
*/
|
||||
|
@ -18,8 +18,6 @@ import org.dromara.hutool.core.io.IORuntimeException;
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.util.ByteUtil;
|
||||
import org.dromara.hutool.core.util.CharsetUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -100,7 +98,7 @@ public class ZipUtilTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void unzipTest() {
|
||||
final File unzip = ZipUtil.unzip("f:/test/mina-maven-3.6.2.zip", "f:\\test");
|
||||
final File unzip = ZipUtil.unzip("f:/test/apache-maven-3.6.2.zip", "f:\\test");
|
||||
Console.log(unzip);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于 Apache FtpServer(http://mina.apache.org/ftpserver-project/)的FTP服务端简单封装。
|
||||
* 基于 Apache FtpServer(http://apache.apache.org/ftpserver-project/)的FTP服务端简单封装。
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.5.0
|
||||
|
@ -66,7 +66,7 @@ public class ArchiverTest {
|
||||
public void sevenZTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.7z");
|
||||
CompressUtil.createArchiver(CharsetUtil.UTF_8, ArchiveStreamFactory.SEVEN_Z, file)
|
||||
.add(FileUtil.file("d:/Java/mina-maven-3.8.1"), (f) -> {
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.8.1"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
@ -78,7 +78,7 @@ public class ArchiverTest {
|
||||
public void tgzTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.tgz");
|
||||
CompressUtil.createArchiver(CharsetUtil.UTF_8, "tgz", file)
|
||||
.add(FileUtil.file("d:/Java/mina-maven-3.8.1"), (f) -> {
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.8.1"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
|
@ -54,15 +54,18 @@ public class JSONStrFormatter {
|
||||
if (null == wrapChar) {
|
||||
//字符串模式开始
|
||||
wrapChar = key;
|
||||
} else if (isEscapeMode) {
|
||||
//在字符串模式下的转义
|
||||
isEscapeMode = false;
|
||||
} else if (wrapChar.equals(key)) {
|
||||
if (isEscapeMode) {
|
||||
//字符串模式下,遇到结束符号,也同时结束转义
|
||||
isEscapeMode = false;
|
||||
}
|
||||
|
||||
//字符串包装结束
|
||||
wrapChar = null;
|
||||
}
|
||||
|
||||
if ((i > 1) && (json.charAt(i - 1) == CharUtil.COLON)) {
|
||||
// 值前加空格
|
||||
result.append(CharUtil.SPACE);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2023. looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* https://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI84V6ITest {
|
||||
@Test
|
||||
void formatTest() {
|
||||
final String a1 = "{'x':'\\n','y':','}";
|
||||
final String formatJsonStr = JSONUtil.formatJsonStr(a1);
|
||||
// Console.log(formatJsonStr);
|
||||
Assertions.assertEquals(
|
||||
"{\n" +
|
||||
" 'x': '\\n',\n" +
|
||||
" 'y': ','\n" +
|
||||
"}", formatJsonStr);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user