From e2514185e8fca3045114d3369185d47860285a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Fri, 27 Nov 2020 22:24:40 +0100 Subject: [PATCH] Fix for videos with double quotes in the title --- explore/graph.mjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/explore/graph.mjs b/explore/graph.mjs index a85a441..ed1622a 100644 --- a/explore/graph.mjs +++ b/explore/graph.mjs @@ -6,6 +6,11 @@ const GRAPH_NODE = ' "%s" [label="%s"]'; const GRAPH_NODE_URL = ' "%s" [label="%s", URL="%s", fontcolor=blue]'; const GRAPH_LINK = ' "%s" -> "%s"'; +/** + * Escape double quotes in a string. + */ +const escapeQuotes = str => str.replace(/"/g, '\\"'); + /** * Convert a graph to the DOT format. * @@ -27,11 +32,11 @@ export const graphToDOT = (graph, title = id => id, url = () => '') => if (url === '') { - return util.format(GRAPH_NODE, id, nodeTitle); + return util.format(GRAPH_NODE, id, escapeQuotes(nodeTitle)); } else { - return util.format(GRAPH_NODE_URL, id, nodeTitle, nodeUrl); + return util.format(GRAPH_NODE_URL, id, escapeQuotes(nodeTitle), nodeUrl); } } ).join('\n');