Skip to content

Commit da0b73c

Browse files
authored
Merge pull request #4981 from VisActor/fix/csv_escape
fix(csv): handle escape option correctly for CSV export
2 parents 8a760ea + 79c8a22 commit da0b73c

5 files changed

Lines changed: 15 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vtable",
5+
"comment": "fix(csv): handle escape option correctly for CSV export",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vtable"
10+
}

docs/assets/guide/en/plugin/table-export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type ExportVTableToExcelOptions = {
4141

4242
export type ExportVTableToCsvOptions = {
4343
formatExportOutput?: (cellInfo: CellInfo) => string | undefined;
44-
escape?: boolean;
44+
escape?: boolean; // Whether to escape special symbols in strings to avoid interfering with CSV parsing, default true
4545
exportAllData?: boolean;
4646
downloadFile?: boolean;
4747
fileName?: string;

docs/assets/guide/zh/plugin/table-export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type ExportVTableToExcelOptions = {
4141

4242
export type ExportVTableToCsvOptions = {
4343
formatExportOutput?: (cellInfo: CellInfo) => string | undefined;
44-
escape?: boolean;
44+
escape?: boolean; // 是否需要将字符串中的特殊符号进行转义,以避免干扰CSV解析,默认为true
4545
exportAllData?: boolean;
4646
downloadFile?: boolean;
4747
fileName?: string;

packages/vtable-export/src/csv/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getCopyCellValue(
7777
}
7878

7979
let value = cellValue;
80-
if (option?.escape) {
80+
if (option?.escape !== false) {
8181
value = escapeForCSV(value);
8282
} else if (typeof value === 'string') {
8383
value = '"' + value + '"';

packages/vtable-plugins/src/table-export/csv/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ function getCopyCellValue(
8181
}
8282

8383
let value = cellValue;
84-
if (option?.escape) {
84+
if (option?.escape !== false) {
85+
//escape默认逻辑改为true,进行转义
8586
value = escapeForCSV(value);
8687
} else if (typeof value === 'string') {
8788
value = '"' + value + '"';

0 commit comments

Comments
 (0)