Skip to content

Commit

Permalink
fix: quote values in tsv export when they contain syntactic characters (
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterckx committed Jan 31, 2025
1 parent de4a048 commit d628a24
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Table/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ function formatDataToTSV(data: TableData[][]): string {
.map((row) => {
return row
.map((data) => {
// Concatenate array values.
if (Array.isArray(data)) {
return data.join(", ");
}
return data;
// Use empty string in place of undefined and null.
if (data === undefined || data === null) return "";
// Convert to string.
const dataString = Array.isArray(data)
? data.join(", ")
: String(data);
// Quote if necessary.
return /[\t\r\n"]/.test(dataString)
? `"${dataString.replaceAll('"', '""')}"`
: dataString;
})
.join("\t");
})
Expand Down

0 comments on commit d628a24

Please sign in to comment.