mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Improve jsonl[...] suite of scriptlets
Reuse original line separator when reassembling JSONL lines.
This commit is contained in:
parent
fbb96c7234
commit
ed9999efd6
1 changed files with 5 additions and 3 deletions
|
|
@ -374,7 +374,8 @@ registerScriptlet(trustedJsonEditFetchResponse, {
|
|||
|
||||
function jsonlEditFn(jsonp, text = '') {
|
||||
const safe = safeSelf();
|
||||
const linesBefore = text.split(/\n+/);
|
||||
const lineSeparator = /\r?\n/.exec(text)?.[0] || '\n';
|
||||
const linesBefore = text.split(lineSeparator);
|
||||
const linesAfter = [];
|
||||
for ( const lineBefore of linesBefore ) {
|
||||
let obj;
|
||||
|
|
@ -387,9 +388,10 @@ function jsonlEditFn(jsonp, text = '') {
|
|||
linesAfter.push(lineBefore);
|
||||
continue;
|
||||
}
|
||||
linesAfter.push(JSONPath.toJSON(obj, safe.JSON_stringify));
|
||||
const lineAfter = safe.JSON_stringify(obj);
|
||||
linesAfter.push(lineAfter);
|
||||
}
|
||||
return linesAfter.join('\n');
|
||||
return linesAfter.join(lineSeparator);
|
||||
}
|
||||
registerScriptlet(jsonlEditFn, {
|
||||
name: 'jsonl-edit.fn',
|
||||
|
|
|
|||
Loading…
Reference in a new issue