mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-06 19:41:51 -04:00
Correctly deserialize HTML entities in block DOM
E.g. in variable names
This commit is contained in:
parent
e4830dfe51
commit
7afb17df7f
3 changed files with 25 additions and 1 deletions
|
@ -156,7 +156,7 @@ const adapter = function (e) {
|
|||
if (typeof e !== 'object') return;
|
||||
if (typeof e.xml !== 'object') return;
|
||||
|
||||
return domToBlocks(html.parseDOM(e.xml.outerHTML));
|
||||
return domToBlocks(html.parseDOM(e.xml.outerHTML, {decodeEntities: true}));
|
||||
};
|
||||
|
||||
module.exports = adapter;
|
||||
|
|
6
test/fixtures/events.json
vendored
6
test/fixtures/events.json
vendored
|
@ -60,6 +60,12 @@
|
|||
"outerHTML": "<block type='operator_equals' id='l^H_{8[DDyDW?m)HIt@b' x='100' y='362'><value name='OPERAND1'><shadow type='text' id='Ud@4y]bc./]uv~te?brb'><field name='TEXT'></field></shadow></value><value name='OPERAND2'><shadow type='text' id='p8[y..,[K;~G,k7]N;08'><field name='TEXT'></field></shadow></value></block>"
|
||||
}
|
||||
},
|
||||
"createvariablewithentity": {
|
||||
"name": "block",
|
||||
"xml": {
|
||||
"outerHTML": "<block type='data_variable' id='/b?}ZGt/N5FmS2yw5GHZ' x='0' y='0'><field name='VARIABLE' id='k-q!YMpHim*lrSX)v(8t' variabletype=''>this & that</field></block>"
|
||||
}
|
||||
},
|
||||
"createobscuredshadow": {
|
||||
"name": "block",
|
||||
"xml": {
|
||||
|
|
|
@ -155,6 +155,24 @@ test('create with obscured shadow', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('create variable with entity in name', t => {
|
||||
const result = adapter(events.createvariablewithentity);
|
||||
|
||||
t.ok(Array.isArray(result));
|
||||
t.equal(result.length, 1);
|
||||
|
||||
t.type(result[0].id, 'string');
|
||||
t.type(result[0].opcode, 'string');
|
||||
t.type(result[0].fields, 'object');
|
||||
t.type(result[0].fields.VARIABLE, 'object');
|
||||
t.type(result[0].fields.VARIABLE.value, 'string');
|
||||
t.equal(result[0].fields.VARIABLE.value, 'this & that');
|
||||
t.type(result[0].inputs, 'object');
|
||||
t.type(result[0].topLevel, 'boolean');
|
||||
t.equal(result[0].topLevel, true);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create with invalid block xml', t => {
|
||||
// Entirely invalid block XML
|
||||
const result = adapter(events.createinvalid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue