From 465b6c8c3060066e64a950313f1b97dae24f0173 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Fri, 27 Dec 2019 11:33:21 +0100 Subject: [PATCH] Escape quotations in statements (fixes #4) --- src/main/java/tfm/graphs/CFGGraph.java | 2 +- src/main/java/tfm/nodes/GraphNode.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/tfm/graphs/CFGGraph.java b/src/main/java/tfm/graphs/CFGGraph.java index f2cfae1..8faf9e3 100644 --- a/src/main/java/tfm/graphs/CFGGraph.java +++ b/src/main/java/tfm/graphs/CFGGraph.java @@ -46,7 +46,7 @@ public class CFGGraph extends Graph { String nodes = getNodes().stream() .sorted(Comparator.comparingInt(GraphNode::getId)) - .map(node -> String.format("%s [label=\"%s: %s\"]", node.getId(), node.getId(), node.getData())) + .map(GraphNode::toGraphvizRepresentation) .collect(Collectors.joining(lineSep)); String arrows = diff --git a/src/main/java/tfm/nodes/GraphNode.java b/src/main/java/tfm/nodes/GraphNode.java index 6226331..133b4cf 100644 --- a/src/main/java/tfm/nodes/GraphNode.java +++ b/src/main/java/tfm/nodes/GraphNode.java @@ -145,7 +145,9 @@ public class GraphNode extends Vertex { } public String toGraphvizRepresentation() { - return String.format("%s[label=\"%s: %s\"];", getId(), getId(), getData()); + String text = getData().replace("\\", "\\\\") + .replace("\"", "\\\""); + return String.format("%s[label=\"%s: %s\"];", getId(), getId(), text); } public Set getDeclaredVariables() { -- GitLab