Decode escaped text in admin JSON views
Build and publish frontend / publish (push) Successful in 53s
Build and publish frontend / publish (push) Successful in 53s
This commit is contained in:
@@ -64,3 +64,18 @@ test('admin JSON responses are readable as accessible collapsible trees', () =>
|
||||
assert.match(page, /JSON\.stringify\(npc\.profile, null, '\\t'\)/);
|
||||
assert.doesNotMatch(page, /jsnview|cdn\.jsdelivr/);
|
||||
});
|
||||
|
||||
test('admin JSON text decodes common JSON and YAML escapes while retaining the stored form', () => {
|
||||
const decoder = page.match(/function decodeEscapedSequences\(text\) \{[\s\S]*?\n \}/);
|
||||
assert.ok(decoder, 'escape decoder should be present');
|
||||
assert.match(page, /Visa lagrad text med escape-tecken/);
|
||||
assert.match(page, /decodeEscapedSequences\(item\)/);
|
||||
const decode = new Function(`${decoder[0]}; return decodeEscapedSequences;`)();
|
||||
|
||||
assert.equal(decode(String.raw`Rad 1\nRad 2`), 'Rad 1\nRad 2');
|
||||
assert.equal(decode(String.raw`Kolumn 1\tKolumn 2`), 'Kolumn 1\tKolumn 2');
|
||||
assert.equal(decode(String.raw`citat: \'hej\'`), "citat: 'hej'");
|
||||
assert.equal(decode(String.raw`\u00E5\x21`), 'å!');
|
||||
assert.equal(decode(String.raw`\U0001F642`), '🙂');
|
||||
assert.equal(decode(String.raw`okänt: \q`), String.raw`okänt: \q`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user