diff --git a/core/generator.js b/core/generator.js index fecc35531..20fb77565 100644 --- a/core/generator.js +++ b/core/generator.js @@ -187,8 +187,9 @@ Blockly.Generator.prototype.blockToCode = function(block) { 'Expecting string from statement block "%s".', block.type); return [this.scrub_(block, code[0]), code[1]]; } else if (goog.isString(code)) { + var id = block.id.replace(/\$/g, '$$$$'); // Issue 251. if (this.STATEMENT_PREFIX) { - code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + block.id + '\'') + + code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + id + '\'') + code; } return this.scrub_(block, code); @@ -297,6 +298,7 @@ Blockly.Generator.prototype.statementToCode = function(block, name) { * @return {string} Loop contents, with infinite loop trap added. */ Blockly.Generator.prototype.addLoopTrap = function(branch, id) { + id = id.replace(/\$/g, '$$$$'); // Issue 251. if (this.INFINITE_LOOP_TRAP) { branch = this.INFINITE_LOOP_TRAP.replace(/%1/g, '\'' + id + '\'') + branch; } diff --git a/core/utils.js b/core/utils.js index 35a10ea58..8d87cdc4d 100644 --- a/core/utils.js +++ b/core/utils.js @@ -543,12 +543,13 @@ Blockly.genUid = function() { }; /** - * Legal characters for the unique ID. - * Should be all on a US keyboard. No XML special characters or control codes. - * Removed $ due to issue 251. + * Legal characters for the unique ID. Should be all on a US keyboard. + * No characters that conflict with XML or JSON. Requests to remove additional + * 'problematic' characters from this soup will be denied. That's your failure + * to properly escape in your own environment. Issues #251, #625, #682. * @private */ -Blockly.genUid.soup_ = '!#%()*+,-./:;=?@[]^_`{|}~' + +Blockly.genUid.soup_ = '!#$%()*+,-./:;=?@[]^_`{|}~' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 4a9737c37..313308d11 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1305,7 +1305,8 @@ Blockly.WorkspaceSvg.prototype.updateGridPattern_ = function() { * .flyoutWidth: Width of the flyout if it is always open. Otherwise zero. * .flyoutHeight: Height of flyout if it is always open. Otherwise zero. * .toolboxPosition: Top, bottom, left or right. - * @return {Object} Contains size and position metrics of a top level workspace. + * @return {!Object} Contains size and position metrics of a top level + * workspace. * @private * @this Blockly.WorkspaceSvg */ diff --git a/tests/generators/unittest.js b/tests/generators/unittest.js index d2b94e66d..5c471d1b7 100644 --- a/tests/generators/unittest.js +++ b/tests/generators/unittest.js @@ -111,7 +111,7 @@ Blockly.Blocks['unittest_adjustindex'] = { "output": "Number", "colour": 65, "tooltip": "Adjusts the value based on whether generated code is using " + - "zero or one based indexing" + "zero or one based indexing." }); } };