Skip to content

Commit d42b2d2

Browse files
pan93412Copilot
andauthored
fix(csv-utils): handle "\r"
Co-authored-by: Copilot <[email protected]>
1 parent 73147a9 commit d42b2d2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/csv-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
export function tableToCSV(columns: string[], rows: string[][]): string {
55
// 轉義 CSV 欄位中的特殊字符
66
const escapeCSVField = (field: string): string => {
7-
// 如果欄位包含逗號、雙引號或換行符,需要用雙引號包圍
8-
if (field.includes(",") || field.includes("\"") || field.includes("\n")) {
7+
// 如果欄位包含逗號、雙引號、換行符或回車符,需要用雙引號包圍
8+
if (field.includes(",") || field.includes("\"") || field.includes("\n") || field.includes("\r")) {
99
// 將雙引號轉義為兩個雙引號
1010
return `"${field.replace(/"/g, "\"\"")}"`;
1111
}

0 commit comments

Comments
 (0)