mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
修复utf8-bom的setting文件读取问题
This commit is contained in:
parent
c70aa5a8e8
commit
15d53726f7
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.21(2023-06-26)
|
# 5.8.21(2023-06-27)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 list 为空时,CollUtil.max等返回null而非异常(pr#1027@Gitee)
|
* 【core 】 list 为空时,CollUtil.max等返回null而非异常(pr#1027@Gitee)
|
||||||
@ -11,6 +11,7 @@
|
|||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复MapUtil工具使用filter方法构造传入参数结果问题(issue#3162@Github)
|
* 【core 】 修复MapUtil工具使用filter方法构造传入参数结果问题(issue#3162@Github)
|
||||||
* 【core 】 修复序列化和反序列化Class问题(issue#I7FQ29@Gitee)
|
* 【core 】 修复序列化和反序列化Class问题(issue#I7FQ29@Gitee)
|
||||||
|
* 【setting】 修复utf8-bom的setting文件读取问题(issue#I7G34E@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.20(2023-06-16)
|
# 5.8.20(2023-06-16)
|
||||||
|
@ -113,7 +113,7 @@ public class SettingLoader {
|
|||||||
if (line == null) {
|
if (line == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
line = line.trim();
|
line = StrUtil.trim(line);
|
||||||
// 跳过注释行和空行
|
// 跳过注释行和空行
|
||||||
if (StrUtil.isBlank(line) || StrUtil.startWith(line, COMMENT_FLAG_PRE)) {
|
if (StrUtil.isBlank(line) || StrUtil.startWith(line, COMMENT_FLAG_PRE)) {
|
||||||
continue;
|
continue;
|
||||||
@ -121,7 +121,7 @@ public class SettingLoader {
|
|||||||
|
|
||||||
// 记录分组名
|
// 记录分组名
|
||||||
if (StrUtil.isSurround(line, CharUtil.BRACKET_START, CharUtil.BRACKET_END)) {
|
if (StrUtil.isSurround(line, CharUtil.BRACKET_START, CharUtil.BRACKET_END)) {
|
||||||
group = line.substring(1, line.length() - 1).trim();
|
group = StrUtil.trim(line.substring(1, line.length() - 1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,12 +131,12 @@ public class SettingLoader {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = keyValue[1].trim();
|
String value = StrUtil.trim(keyValue[1]);
|
||||||
// 替换值中的所有变量变量(变量必须是此行之前定义的变量,否则无法找到)
|
// 替换值中的所有变量变量(变量必须是此行之前定义的变量,否则无法找到)
|
||||||
if (this.isUseVariable) {
|
if (this.isUseVariable) {
|
||||||
value = replaceVar(group, value);
|
value = replaceVar(group, value);
|
||||||
}
|
}
|
||||||
this.groupedMap.put(group, keyValue[0].trim(), value);
|
this.groupedMap.put(group, StrUtil.trim(keyValue[0]), value);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.close(reader);
|
IoUtil.close(reader);
|
||||||
|
27
hutool-setting/src/test/java/cn/hutool/setting/IssueI7G34ETest.java
Executable file
27
hutool-setting/src/test/java/cn/hutool/setting/IssueI7G34ETest.java
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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:
|
||||||
|
* http://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 cn.hutool.setting;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class IssueI7G34ETest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readWithBomTest() {
|
||||||
|
final Setting setting = new Setting("test_with_bom.setting");
|
||||||
|
final String s = setting.get("line1", "key1");
|
||||||
|
|
||||||
|
Assert.assertEquals("value1", s);
|
||||||
|
}
|
||||||
|
}
|
3
hutool-setting/src/test/resources/test_with_bom.setting
Executable file
3
hutool-setting/src/test/resources/test_with_bom.setting
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
[line1]
|
||||||
|
key1 = value1
|
||||||
|
key2 = value2
|
Loading…
Reference in New Issue
Block a user