From 80b4dab1048e3e1d6a65a96f6f1491fc567a0f99 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 29 Nov 2017 10:34:00 -0500 Subject: [PATCH 1/3] Decode the encoded argument information --- package.json | 1 + src/engine/mutation-adapter.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ccc8089..aa5de51a 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "babel-loader": "^7.0.0", "babel-preset-es2015": "^6.24.1", "copy-webpack-plugin": "4.2.1", + "decode-html": "2.0.0", "escape-html": "1.0.3", "eslint": "^4.5.0", "eslint-config-scratch": "^5.0.0", diff --git a/src/engine/mutation-adapter.js b/src/engine/mutation-adapter.js index c40052ff..d1984d30 100644 --- a/src/engine/mutation-adapter.js +++ b/src/engine/mutation-adapter.js @@ -1,4 +1,5 @@ const html = require('htmlparser2'); +const decodeHtml = require('decode-html'); /** * Convert a part of a mutation DOM to a mutation VM object, recursively. @@ -11,7 +12,7 @@ const mutatorTagToObject = function (dom) { obj.children = []; for (const prop in dom.attribs) { if (prop === 'xmlns') continue; - obj[prop] = dom.attribs[prop]; + obj[prop] = decodeHtml(dom.attribs[prop]); } for (let i = 0; i < dom.children.length; i++) { obj.children.push( From 5a53323715f9cdf7b270d33dc2ec12babf0840ce Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 29 Nov 2017 12:00:00 -0500 Subject: [PATCH 2/3] Update to use explicit procedure names and ids --- src/blocks/scratch3_procedures.js | 8 ++++---- src/engine/block-utility.js | 4 ++-- src/engine/blocks.js | 9 +++++---- test/unit/blocks_procedures.js | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/blocks/scratch3_procedures.js b/src/blocks/scratch3_procedures.js index 22e2f788..645e582e 100644 --- a/src/blocks/scratch3_procedures.js +++ b/src/blocks/scratch3_procedures.js @@ -27,7 +27,7 @@ class Scratch3ProcedureBlocks { call (args, util) { if (!util.stackFrame.executed) { const procedureCode = args.mutation.proccode; - const paramNames = util.getProcedureParamNames(procedureCode); + const [paramNames, paramIds] = util.getProcedureParamNamesAndIds(procedureCode); // If null, procedure could not be found, which can happen if custom // block is dragged between sprites without the definition. @@ -36,9 +36,9 @@ class Scratch3ProcedureBlocks { return; } - for (let i = 0; i < paramNames.length; i++) { - if (args.hasOwnProperty(`input${i}`)) { - util.pushParam(paramNames[i], args[`input${i}`]); + for (let i = 0; i < paramIds.length; i++) { + if (args.hasOwnProperty(paramIds[i])) { + util.pushParam(paramNames[i], args[paramIds[i]]); } } diff --git a/src/engine/block-utility.js b/src/engine/block-utility.js index 9fee1f7b..6ecab07d 100644 --- a/src/engine/block-utility.js +++ b/src/engine/block-utility.js @@ -97,8 +97,8 @@ class BlockUtility { * @param {string} procedureCode Procedure code for procedure to query. * @return {Array.} List of param names for a procedure. */ - getProcedureParamNames (procedureCode) { - return this.thread.target.blocks.getProcedureParamNames(procedureCode); + getProcedureParamNamesAndIds (procedureCode) { + return this.thread.target.blocks.getProcedureParamNamesAndIds(procedureCode); } /** diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 82c5e21c..5b330afc 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -206,7 +206,7 @@ class Blocks { * @param {?string} name Name of procedure to query. * @return {?Array.} List of param names for a procedure. */ - getProcedureParamNames (name) { + getProcedureParamNamesAndIds (name) { const cachedNames = this._cache.procedureParamNames[name]; if (typeof cachedNames !== 'undefined') { return cachedNames; @@ -217,9 +217,10 @@ class Blocks { const block = this._blocks[id]; if (block.opcode === 'procedures_prototype' && block.mutation.proccode === name) { - const paramNames = JSON.parse(block.mutation.argumentnames); - this._cache.procedureParamNames[name] = paramNames; - return paramNames; + const names = JSON.parse(block.mutation.argumentnames); + const ids = JSON.parse(block.mutation.argumentids); + this._cache.procedureParamNames[name] = [names, ids]; + return this._cache.procedureParamNames[name]; } } diff --git a/test/unit/blocks_procedures.js b/test/unit/blocks_procedures.js index cab5e04e..0285b23d 100644 --- a/test/unit/blocks_procedures.js +++ b/test/unit/blocks_procedures.js @@ -16,7 +16,7 @@ test('calling a custom block with no definition does not throw', t => { } }; const util = { - getProcedureParamNames: () => null, + getProcedureParamNamesAndIds: () => null, stackFrame: { executed: false } From 6b00f97804d00db2fa9b1fdb98e7577101252cf9 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 29 Nov 2017 15:46:04 -0500 Subject: [PATCH 3/3] Fix test --- test/unit/blocks_procedures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/blocks_procedures.js b/test/unit/blocks_procedures.js index 0285b23d..5dfecea7 100644 --- a/test/unit/blocks_procedures.js +++ b/test/unit/blocks_procedures.js @@ -16,7 +16,7 @@ test('calling a custom block with no definition does not throw', t => { } }; const util = { - getProcedureParamNamesAndIds: () => null, + getProcedureParamNamesAndIds: () => [null, null], stackFrame: { executed: false }