Skip to content
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

DYN-1261 Escape StringInputNode value when converting NodeToCode #11295

Merged
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
8 changes: 7 additions & 1 deletion src/Libraries/CoreNodeModels/Input/BaseTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ protected override void DeserializeCore(XmlElement nodeElement, SaveContext cont

internal override IEnumerable<AssociativeNode> BuildAst(List<AssociativeNode> inputAstNodes, CompilationContext context)
{
var rhs = AstFactory.BuildStringNode(Value);
string value = Value;
if (context == CompilationContext.NodeToCode)
{
value = value.Replace(@"\", @"\\")
.Replace("\"", "\\\"");
}
var rhs = AstFactory.BuildStringNode(value);
var assignment = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), rhs);

return new[] { assignment };
Expand Down
30 changes: 30 additions & 0 deletions test/DynamoCoreTests/NodeToCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,36 @@ public void TestNodeToCodeUndoRecorder()
Assert.AreEqual(0, recorder.ActionCount());
}

[Test]
public void TestNodeToCodeStringInputEscaping()
{
// Arrange
OpenModel(@"core\node2code\stringNodesInNeedOfEscaping.dyn");
var nodes = CurrentDynamoModel.CurrentWorkspace.Nodes;
var engine = CurrentDynamoModel.EngineController;

// Act
var nodesToCode = engine.ConvertNodesToCode(nodes, nodes);
var results = nodesToCode.AstNodes.OfType<BinaryExpressionNode>()
.Where((x, i) => i < 8)
.Select(x => x.RightNode.ToString())
.ToList();

// Assert
var expect = new List<string>
{
"\"C:\\\\\"", // "C:\\"
"\"4\\\"\"", // "4\""
"\"\\\"Hello, world.\\\"\"", // "\"Hello, world.\""
"\"Hello\\\\r\\\\nWorld\"", // "Hello\\r\\nWorld"
"\"\\\\tHello World\"", // "\\tHello World"
"\"\\\\u33A1\"", // "\\u33A1"
"\"\\\\u00B2\"", // "\\u00B2"
"\"\\\\\\\\SERVER\\\\PATH\"" // "\\\\SERVER\\PATH"
};
Assert.AreEqual(expect, results);
}

[Test]
public void TestUINode_String()
{
Expand Down
Loading