Skip to content

Don't allow illegal connections to procedure prototype blocks #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,15 @@ Blockly.Connection.prototype.canConnectWithReason_ = function(target) {
return Blockly.Connection.REASON_CHECKS_FAILED;
} else if (blockA.isShadow() && !blockB.isShadow()) {
return Blockly.Connection.REASON_SHADOW_PARENT;
} else if (blockA.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE &&
blockB.type != 'procedures_prototype' &&
superiorConn == blockA.getInput('custom_block').connection ) {
} else if ((blockA.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE &&
blockB.type != Blockly.PROCEDURES_PROTOTYPE_BLOCK_TYPE &&
superiorConn == blockA.getInput('custom_block').connection) ||
(blockB.type == Blockly.PROCEDURES_PROTOTYPE_BLOCK_TYPE &&
blockA.type != Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE)) {
// Hack to fix #1127: Fail attempts to connect to the custom_block input
// on a defnoreturn block, unless the connecting block is a specific type.
// And hack to fix #1534: Fail attempts to connect anything but a
// defnoreturn block to a prototype block.
return Blockly.Connection.REASON_CUSTOM_PROCEDURE;
}
return Blockly.Connection.CAN_CONNECT;
Expand Down
9 changes: 9 additions & 0 deletions tests/custom_procedure_playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@
</value>
</block>
</category>
<category name="Statements">
<block type="control_forever"></block>
<block type="sound_stopallsounds"></block>
<block type="control_start_as_clone"></block>
<block type="control_stop">
<mutation hasnext="false"></mutation>
<field name="STOP_OPTION">all</field>
</block>
</category>
</xml>

<script>
Expand Down