Skip to content

Commit 7e8fe7f

Browse files
authored
Prevent escaping copy data that was explictly specified (#1048)
1 parent 2257ccb commit 7e8fe7f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/core/src/data-editor/copy-paste.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/* eslint-disable sonarjs/no-duplicate-string */
22
import { assertNever } from "../common/support.js";
33
import {
4-
GridCellKind,
5-
type GridCell,
64
BooleanEmpty,
75
BooleanIndeterminate,
6+
GridCellKind,
7+
type GridCell,
88
} from "../internal/data-grid/data-grid-types.js";
99

1010
type StringArrayCellBuffer = {
1111
formatted: string[];
1212
rawValue: string[];
1313
format: "string-array";
14+
doNotEscape?: boolean;
1415
};
1516

1617
type BasicCellBuffer = {
1718
formatted: string;
1819
rawValue: string | number | boolean | BooleanEmpty | BooleanIndeterminate | undefined;
1920
format: "string" | "number" | "boolean" | "url";
21+
doNotEscape?: boolean;
2022
};
2123
export type CellBuffer = StringArrayCellBuffer | BasicCellBuffer;
2224
export type CopyBuffer = CellBuffer[][];
@@ -27,6 +29,8 @@ function convertCellToBuffer(cell: GridCell): CellBuffer {
2729
formatted: cell.copyData,
2830
rawValue: cell.copyData,
2931
format: "string",
32+
// Do not escape the copy value if it was explicitly specified via copyData:
33+
doNotEscape: true,
3034
};
3135
}
3236
switch (cell.kind) {
@@ -140,7 +144,7 @@ function createTextBuffer(copyBuffer: CopyBuffer): string {
140144
} else if (cell.format === "string-array") {
141145
line.push(cell.formatted.map(x => escapeIfNeeded(x, true)).join(","));
142146
} else {
143-
line.push(escapeIfNeeded(cell.formatted, false));
147+
line.push(cell.doNotEscape === true ? cell.formatted : escapeIfNeeded(cell.formatted, false));
144148
}
145149
}
146150
lines.push(line.join("\t"));

0 commit comments

Comments
 (0)