From 570486d8c01eca68c13ace1aeb572d57adb1e108 Mon Sep 17 00:00:00 2001 From: aparajit-pratap Date: Mon, 26 Nov 2018 12:27:57 -0500 Subject: [PATCH] Fix crash with incorrect syntax in CBN in custom node (#9258) * fix crash with cbn in custom node * add recorded test * add test description --- .../Engine/CodeGeneration/AstBuilder.cs | 2 +- test/DynamoCoreWpfTests/RecordedTests.cs | 14 ++++++++ .../recorded/CreateCustomNodeSyntaxError.xml | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/core/recorded/CreateCustomNodeSyntaxError.xml diff --git a/src/DynamoCore/Engine/CodeGeneration/AstBuilder.cs b/src/DynamoCore/Engine/CodeGeneration/AstBuilder.cs index 0a6a2447564..4b828b98ce0 100644 --- a/src/DynamoCore/Engine/CodeGeneration/AstBuilder.cs +++ b/src/DynamoCore/Engine/CodeGeneration/AstBuilder.cs @@ -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)); } diff --git a/test/DynamoCoreWpfTests/RecordedTests.cs b/test/DynamoCoreWpfTests/RecordedTests.cs index 5c2e460fa7d..d8de0f9f044 100644 --- a/test/DynamoCoreWpfTests/RecordedTests.cs +++ b/test/DynamoCoreWpfTests/RecordedTests.cs @@ -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() { diff --git a/test/core/recorded/CreateCustomNodeSyntaxError.xml b/test/core/recorded/CreateCustomNodeSyntaxError.xml new file mode 100644 index 00000000000..80b3c5bee68 --- /dev/null +++ b/test/core/recorded/CreateCustomNodeSyntaxError.xml @@ -0,0 +1,32 @@ + + + 00000000-0000-0000-0000-000000000000 + + + 0ebfb690-5ed7-4cc1-ac59-f797c3c330a2 + + + 00000000-0000-0000-0000-000000000000 + + + d826ffc3-759e-4eb6-968e-82c0fa0a13f2 + + + + + + d826ffc3-759e-4eb6-968e-82c0fa0a13f2 + + + 00000000-0000-0000-0000-000000000000 + + + d826ffc3-759e-4eb6-968e-82c0fa0a13f2 + + + 00000000-0000-0000-0000-000000000000 + + + d826ffc3-759e-4eb6-968e-82c0fa0a13f2 + + \ No newline at end of file