feat(editor): support atomic multi-cell CSV paste

This commit is contained in:
Anya Tokugawa committed 2026-11-08 21:48:32 +09:00
1 parent 2d6ceac0d7
commit 09afb438c9
7 files changed
+88 -11

No files matched your search

+31
View File
@@ -29,3 +29,34 @@ test('Quotes, HTML, formulas and newlines remain inert CSV data',()=>{
assert.ok(source.endsWith(',unchanged\r\n'));
}
});
test('Tab-separated paste preserves untouched CSV bytes and treats commas as data',()=>{
const source='\ufeff"keep",old,last\r\n"unchanged",x,y\n';
assert.equal(csv.paste(source,0,1,'日本語,値\t"a""b"\r\nnext\tfinal\r\n'),
'\ufeff"keep","日本語,値","a""b"\r\n"unchanged",next,final\n');
assert.equal(csv.paste(source,0,0,'keep\told\tlast\nunchanged\tx\ty\n'),source);
assert.equal(csv.paste('a,b\n',0,0,'"line1\r\nline2"\t"tab\tvalue"\n'),'"line1\nline2",tab\tvalue\n');
});
test('Paste grows only required rows and cells, preserving ragged data',()=>{
assert.equal(csv.paste('a,b\nc\nz\n',0,1,'x\ty\nz'),'a,x,y\nc,z\nz\n');
assert.equal(csv.paste('a,b',0,1,'x\ty\nz\tw'),'a,x,y\r\n,z,w\r\n');
assert.equal(csv.paste('',0,0,'a\tb\n'),'a,b\r\n');
assert.equal(csv.paste('a,b\n',0,0,'\t\n'),',\n');
assert.equal(csv.paste('a,b\n',0,0,''),'a,b\n');
});
test('Paste validates both input and final CSV size without partial writes',()=>{
const source='original,untouched\r\n';
for(const text of ['a\tb\n"unfinished','a\0b\tc','x'.repeat(16385)+'\tb','a\n'.repeat(201),'a\t'.repeat(32)])assert.throws(()=>csv.paste(source,0,0,text));
for(const [row,col] of [[-1,0],[0,-1],[0.5,0],[0,NaN],[200,0],[0,32]])assert.throws(()=>csv.paste(source,row,col,'a\tb'));
assert.throws(()=>csv.paste(source,199,0,'a\nb'));
assert.throws(()=>csv.paste(source,0,31,'a\tb'));
// Valid individual cells can still exceed the total document limit.
const big=Array(16).fill('x'.repeat(16000)).join(',');
assert.throws(()=>csv.paste(big,0,16,'y'.repeat(16000)));
// Quoting comma-heavy clipboard data expands the resulting CSV.
assert.throws(()=>csv.paste('',0,0,Array(16).fill(','.repeat(16383)).join('\t')));
assert.equal(source,'original,untouched\r\n');
});
test('Pasted HTML, macros and formulas remain values rather than executable content',()=>{
const values=['<img src=x onerror=alert(1)>','{{children}}','=SUM(A1:A9)'];
assert.deepEqual(csv.parse(csv.paste('',0,0,values.join('\t'))).rows[0].cells.map(c=>c.value),values);
});