Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): preserve surrogate pairs in truncated CSV cells #27497

Mergedmacodev00(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/27497/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 43 additions and 2 deletions.

x
0 of 2 viewed, 2 left
33 additions and 0 deletionspackages/shared/src/delimitedPreview.test.tsModified
View file
@@ -59,6 +59,39 @@
expect(table.rows[0]?.[0]).toHaveLength(2000);
expect(parseDelimitedPreview('a,"unfinished', ",").truncated).toBe(true);
});
+ describe.each([",", "\t"] as const)("Unicode cells with delimiter %j", (delimiter) => {
+ it.each([false, true])("does not split surrogate pairs in quoted=%s cells", (quoted) => {
+ const prefix = "x".repeat(1999);
+ const value = `${prefix}😀tail`;
+ const input = `${quoted ? `"${value}"` : value}${delimiter}next\nlast`;
+ expect(parseDelimitedPreview(input, delimiter)).toEqual({
+ rows: [[prefix, "next"], ["last"]],
+ truncated: true,
+ });
+ });
+ it("keeps pairs that fit and truncates later characters", () => {
+ const value = `${"x".repeat(1998)}😀`;
+ expect(parseDelimitedPreview(value, delimiter)).toEqual({
+ rows: [[value]],
+ truncated: false,
+ });
+ expect(parseDelimitedPreview(`${value}tail`, delimiter)).toEqual({
+ rows: [[value]],
+ truncated: true,
+ });
+ });
+ it("keeps escaped quotes and BMP text at the same limit", () => {
+ const prefix = "x".repeat(1999);
+ expect(parseDelimitedPreview(`"${prefix}""tail"`, delimiter)).toEqual({
+ rows: [[`${prefix}"`]],
+ truncated: true,