Unverified Commit c015c8f3 authored by Beka Westberg's avatar Beka Westberg Committed by GitHub

Fix nullptr in text connection check (#2206)

parent 1ece0851
...@@ -36,8 +36,12 @@ Blockly.Blocks['text'] = { ...@@ -36,8 +36,12 @@ Blockly.Blocks['text'] = {
}; };
Blockly.Blocks.text.connectionCheck = function (myConnection, otherConnection, opt_value) { Blockly.Blocks.text.connectionCheck = function (myConnection, otherConnection, opt_value) {
var block = myConnection.sourceBlock_;
var otherTypeArray = otherConnection.check_; var otherTypeArray = otherConnection.check_;
if (!otherTypeArray) { // Other connection accepts everything.
return true;
}
var block = myConnection.sourceBlock_;
var shouldIgnoreError = Blockly.mainWorkspace.isLoading; var shouldIgnoreError = Blockly.mainWorkspace.isLoading;
var value = opt_value || block.getFieldValue('TEXT'); var value = opt_value || block.getFieldValue('TEXT');
......
...@@ -39,6 +39,7 @@ suite('Text Blocks', function() { ...@@ -39,6 +39,7 @@ suite('Text Blocks', function() {
var string = { check_: ['String'] }; var string = { check_: ['String'] };
var key = { check_: ['Key'] }; var key = { check_: ['Key'] };
var many = { check_: ['Number', 'String'] }; var many = { check_: ['Number', 'String'] };
var untyped = { check_: null };
var invalidNumbers = [ var invalidNumbers = [
'cat', '4cat', 'e', ' zero ', '0x0', '.', '-', '+', '', '-e-', '+e+' 'cat', '4cat', 'e', ' zero ', '0x0', '.', '-', '+', '', '-e-', '+e+'
]; ];
...@@ -83,6 +84,14 @@ suite('Text Blocks', function() { ...@@ -83,6 +84,14 @@ suite('Text Blocks', function() {
test('Should connect with many checks', function() { test('Should connect with many checks', function() {
chai.assert.isTrue(check(mockConnection('cat'), many)); chai.assert.isTrue(check(mockConnection('cat'), many));
}) });
test('Should connect to untyped when a number', function() {
chai.assert.isTrue(check(mockConnection('1'), untyped));
});
test('Should connect to untyped when not number', function() {
chai.assert.isTrue(check(mockConnection('cat'), untyped));
});
}); });
}) })
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment