Correctly deserialize HTML entities in block DOM

E.g. in variable names
This commit is contained in:
Scimonster 2017-10-09 01:19:55 +03:00
parent e4830dfe51
commit 7afb17df7f
3 changed files with 25 additions and 1 deletions
src/engine
test

View file

@ -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;

View file

@ -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 &amp; that</field></block>"
}
},
"createobscuredshadow": {
"name": "block",
"xml": {

View file

@ -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);