mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
const test = require('tap').test;
|
|
const xml = require('../../src/util/xml-escape');
|
|
|
|
test('escape', t => {
|
|
const input = '<foo bar="he & llo \'"></foo>';
|
|
const output = '<foo bar="he & llo '"></foo>';
|
|
t.strictEqual(xml(input), output);
|
|
t.end();
|
|
});
|
|
|
|
test('xmlEscape (more)', t => {
|
|
const empty = '';
|
|
t.equal(xml(empty), empty);
|
|
|
|
const safe = 'hello';
|
|
t.equal(xml(safe), safe);
|
|
|
|
const unsafe = '< > & \' "';
|
|
t.equal(xml(unsafe), '< > & ' "');
|
|
|
|
const single = '&';
|
|
t.equal(xml(single), '&');
|
|
|
|
const mix = '<a>b& c\'def_-"';
|
|
t.equal(xml(mix), '<a>b& c'def_-"');
|
|
|
|
const dupes = '<<&_"_"_&>>';
|
|
t.equal(xml(dupes), '<<&_"_"_&>>');
|
|
|
|
const emoji = '(>^_^)>';
|
|
t.equal(xml(emoji), '(>^_^)>');
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('xmlEscape should handle non strings', t => {
|
|
const array = ['hello', 'world'];
|
|
t.equal(xml(array), String(array));
|
|
|
|
const arrayWithSpecialChar = ['hello', '<world>'];
|
|
t.equal(xml(arrayWithSpecialChar), 'hello,<world>');
|
|
|
|
const arrayWithNumbers = [1, 2, 3];
|
|
t.equal(xml(arrayWithNumbers), '1,2,3');
|
|
|
|
// Objects shouldn't get provided to replaceUnsafeChars, but in the event
|
|
// they do, it should just return the object (and log an error)
|
|
const object = {hello: 'world'};
|
|
t.equal(xml(object), object);
|
|
|
|
t.end();
|
|
});
|