修复utf8-bom的setting文件读取问题

This commit is contained in:
Looly 2023-06-27 10:17:00 +08:00
parent c70aa5a8e8
commit 15d53726f7
4 changed files with 36 additions and 5 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.21(2023-06-26)
# 5.8.21(2023-06-27)
### 🐣新特性
* 【core 】 list 为空时CollUtil.max等返回null而非异常pr#1027@Gitee
@ -11,6 +11,7 @@
### 🐞Bug修复
* 【core 】 修复MapUtil工具使用filter方法构造传入参数结果问题issue#3162@Github
* 【core 】 修复序列化和反序列化Class问题issue#I7FQ29@Gitee
* 【setting】 修复utf8-bom的setting文件读取问题issue#I7G34E@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.20(2023-06-16)

View File

@ -113,7 +113,7 @@ public class SettingLoader {
if (line == null) {
break;
}
line = line.trim();
line = StrUtil.trim(line);
// 跳过注释行和空行
if (StrUtil.isBlank(line) || StrUtil.startWith(line, COMMENT_FLAG_PRE)) {
continue;
@ -121,7 +121,7 @@ public class SettingLoader {
// 记录分组名
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;
}
@ -131,12 +131,12 @@ public class SettingLoader {
continue;
}
String value = keyValue[1].trim();
String value = StrUtil.trim(keyValue[1]);
// 替换值中的所有变量变量变量必须是此行之前定义的变量否则无法找到
if (this.isUseVariable) {
value = replaceVar(group, value);
}
this.groupedMap.put(group, keyValue[0].trim(), value);
this.groupedMap.put(group, StrUtil.trim(keyValue[0]), value);
}
} finally {
IoUtil.close(reader);

View 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);
}
}

View File

@ -0,0 +1,3 @@
[line1]
key1 = value1
key2 = value2