Skip to content

Commit

Permalink
修复\n#出现在双引号中解析错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Jul 1, 2024
1 parent db5806f commit f4d67ed
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 🚀Changelog

-------------------------------------------------------------------------------------------------------------
# 5.8.29(2024-06-30)
# 5.8.29(2024-07-01)

### 🐣新特性
* 【core 】 DateUtil增加offsetYear方法
Expand All @@ -27,6 +27,7 @@
* 【http 】 修复Mac下的微信浏览器被识别为移动端问题(issue#IA74K2@Gitee)
* 【core 】 修复Tailer指定初始读取行数的计算错误问题(issue#IA77ML@Gitee)
* 【http 】 修复getFileNameFromDisposition获取头错误问题(issue#3632@Github)
* 【core 】 修复\n#出现在双引号中解析错误问题(issue#IA8WE0@Gitee)

-------------------------------------------------------------------------------------------------------------
# 5.8.28(2024-05-29)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ private List<String> readLine() throws IORuntimeException {
if(preChar < 0 || preChar == CharUtil.CR || preChar == CharUtil.LF){
// 判断行首字符为指定注释字符的注释开始,直到遇到换行符
// 行首分两种,1是preChar < 0表示文本开始,2是换行符后紧跟就是下一行的开始
if(null != this.config.commentCharacter && c == this.config.commentCharacter){
// issue#IA8WE0 如果注释符出现在包装符内,被认为是普通字符
if((false == inQuotes) && null != this.config.commentCharacter && c == this.config.commentCharacter){
inComment = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cn.hutool.core.text.csv;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
* https://gitee.com/dromara/hutool/issues/IA8WE0
*/
public class IssueIA8WE0Test {
@Test
public void csvReadTest() {
final CsvReader csvReader = new CsvReader();
final CsvData read = csvReader.read(FileUtil.file("issueIA8WE0.csv"));
final List<CsvRow> rows = read.getRows();

assertEquals(1, rows.size());
assertEquals(3, rows.get(0).size());
assertEquals("c1_text1", rows.get(0).get(0));
// 如果\n#出现在双引号中,表示实际的文本内容,并不算注释
assertEquals("c1_text2\n#c1_text2_line2", rows.get(0).get(1));
assertEquals("c1_text3", rows.get(0).get(2));

IoUtil.close(csvReader);
}
}
2 changes: 2 additions & 0 deletions hutool-core/src/test/resources/issueIA8WE0.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
c1_text1,"c1_text2
#c1_text2_line2",c1_text3

0 comments on commit f4d67ed

Please sign in to comment.