Skip to content

Commit ed9999e

Browse files
committed
Improve jsonl[...] suite of scriptlets
Reuse original line separator when reassembling JSONL lines.
1 parent fbb96c7 commit ed9999e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/js/resources/json-edit.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ registerScriptlet(trustedJsonEditFetchResponse, {
374374

375375
function jsonlEditFn(jsonp, text = '') {
376376
const safe = safeSelf();
377-
const linesBefore = text.split(/\n+/);
377+
const lineSeparator = /\r?\n/.exec(text)?.[0] || '\n';
378+
const linesBefore = text.split(lineSeparator);
378379
const linesAfter = [];
379380
for ( const lineBefore of linesBefore ) {
380381
let obj;
@@ -387,9 +388,10 @@ function jsonlEditFn(jsonp, text = '') {
387388
linesAfter.push(lineBefore);
388389
continue;
389390
}
390-
linesAfter.push(JSONPath.toJSON(obj, safe.JSON_stringify));
391+
const lineAfter = safe.JSON_stringify(obj);
392+
linesAfter.push(lineAfter);
391393
}
392-
return linesAfter.join('\n');
394+
return linesAfter.join(lineSeparator);
393395
}
394396
registerScriptlet(jsonlEditFn, {
395397
name: 'jsonl-edit.fn',

0 commit comments

Comments
 (0)