Skip to content

Commit

Permalink
Fix crash with incorrect syntax in CBN in custom node (#9258)
Browse files Browse the repository at this point in the history
* fix crash with cbn in custom node

* add recorded test

* add test description
  • Loading branch information
aparajit-pratap authored Nov 26, 2018
1 parent 896e0b2 commit 570486d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DynamoCore/Engine/CodeGeneration/AstBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ internal void CompileCustomNodeDefinition(
else
{
// For single output, directly return that identifier or null.
AssociativeNode returnValue = outputs.Count == 1 ? outputs[0] : new NullNode();
AssociativeNode returnValue = outputs.Count == 1 && outputs[0] != null ? outputs[0] : new NullNode();
functionBody.Body.Add(AstFactory.BuildReturnStatement(returnValue));
}

Expand Down
14 changes: 14 additions & 0 deletions test/DynamoCoreWpfTests/RecordedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,20 @@ public void TestCustomNode()
AssertPreviewValue("04f6dab5-0a0b-4563-9f20-d0e58fcae7a5", 1.0);
}

[Test]
public void TestCustomNodeSyntaxError_DoesNotCrash()
{
//Create custom node
//Scenario:
//1. Create custom node
//2. Create code block node
//3. Type in a range expression (1..10) and commit the node
//4. Update the code block by introducing syntax error like "1...10"
//5. Test for crash
Assert.DoesNotThrow(() => RunCommandsFromFile("CreateCustomNodeSyntaxError.xml"));
}


[Test]
public void TestCustomNodeUI()
{
Expand Down
32 changes: 32 additions & 0 deletions test/core/recorded/CreateCustomNodeSyntaxError.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Commands ExitAfterPlayback="true" PauseAfterPlaybackInMs="10" CommandIntervalInMs="20">
<SelectModelCommand Modifiers="0">
<ModelGuid>00000000-0000-0000-0000-000000000000</ModelGuid>
</SelectModelCommand>
<CreateCustomNodeCommand Name="fdg" Category="Fdsg" Description="fdgs" MakeCurrent="true">
<ModelGuid>0ebfb690-5ed7-4cc1-ac59-f797c3c330a2</ModelGuid>
</CreateCustomNodeCommand>
<SelectModelCommand Modifiers="0">
<ModelGuid>00000000-0000-0000-0000-000000000000</ModelGuid>
</SelectModelCommand>
<CreateNodeCommand X="357.333333333333" Y="231.333333333333" DefaultPosition="false" TransformCoordinates="true">
<ModelGuid>d826ffc3-759e-4eb6-968e-82c0fa0a13f2</ModelGuid>
<Dynamo.Graph.Nodes.CodeBlockNodeModel guid="d826ffc3-759e-4eb6-968e-82c0fa0a13f2" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="265" y="200" isVisible="true" lacing="Disabled" isSelectedInput="False" isSelectedOutput="False" IsFrozen="false" isPinned="false" CodeText="1...10;" ShouldFocus="false">
<OutPortInfo LineIndex="0" />
</Dynamo.Graph.Nodes.CodeBlockNodeModel>
</CreateNodeCommand>
<UpdateModelValueCommand Name="Code" Value="1...10" WorkspaceGuid="e6953cd6-586f-442f-845c-cd7d93dacbc6">
<ModelGuid>d826ffc3-759e-4eb6-968e-82c0fa0a13f2</ModelGuid>
</UpdateModelValueCommand>
<SelectModelCommand Modifiers="0">
<ModelGuid>00000000-0000-0000-0000-000000000000</ModelGuid>
</SelectModelCommand>
<UpdateModelValueCommand Name="Code" Value="1..10;" WorkspaceGuid="e6953cd6-586f-442f-845c-cd7d93dacbc6">
<ModelGuid>d826ffc3-759e-4eb6-968e-82c0fa0a13f2</ModelGuid>
</UpdateModelValueCommand>
<SelectModelCommand Modifiers="0">
<ModelGuid>00000000-0000-0000-0000-000000000000</ModelGuid>
</SelectModelCommand>
<UpdateModelValueCommand Name="Code" Value="1...10;" WorkspaceGuid="e6953cd6-586f-442f-845c-cd7d93dacbc6">
<ModelGuid>d826ffc3-759e-4eb6-968e-82c0fa0a13f2</ModelGuid>
</UpdateModelValueCommand>
</Commands>

0 comments on commit 570486d

Please sign in to comment.