]> granicus.if.org Git - graphviz/commitdiff
fix: unescaped backslashes in graph labels in xdot output
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 21 Jul 2020 01:00:37 +0000 (18:00 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 21 Jul 2020 01:00:37 +0000 (18:00 -0700)
Variant of #165.

plugin/core/gvrender_core_dot.c
rtest/165_3.dot [new file with mode: 0644]
rtest/test_regression.py

index a2d9b8f1b5b95938863226fe3ea3009c103523f3..c125800c3c9cecb330021774802ab439485d2e7e 100644 (file)
@@ -516,7 +516,7 @@ static void xdot_end_graph(graph_t* g)
        agxset(g, xd->g_draw, agxbuse(xbufs[EMIT_GDRAW]));
     }
     if (GD_label(g))
-       agxset(g, xd->g_l_draw, agxbuse(xbufs[EMIT_GLABEL]));
+       put_escaping_backslashes(g, xd->g_l_draw, agxbuse(xbufs[EMIT_GLABEL]));
     agsafeset (g, "xdotversion", xd->version_s, "");
 
     for (i = 0; i < NUMXBUFS; i++)
diff --git a/rtest/165_3.dot b/rtest/165_3.dot
new file mode 100644 (file)
index 0000000..e211399
--- /dev/null
@@ -0,0 +1,5 @@
+// see test_regression.py:test_165_3()
+digraph {
+  label="hello \\\" world";
+  a;
+}
index 98f6f1c0fd356184fa24e5047e0b6ce2816f5293..3ad68621fa3cf69a2de4618b6a38587a94374f32 100644 (file)
@@ -77,6 +77,28 @@ def test_165_2():
     assert any(r'hello \\\" world' in l for l in ldraw), \
       'unexpected ldraw contents'
 
+def test_165_3():
+    '''
+    variant of test_165() that checks a similar problem for graph labels
+    https://gitlab.com/graphviz/graphviz/-/issues/165
+    '''
+
+    # locate our associated test case in this directory
+    input = os.path.join(os.path.dirname(__file__), '165_3.dot')
+    assert os.path.exists(input), 'unexpectedly missing test case'
+
+    # ask Graphviz to translate it to xdot
+    output = subprocess.check_output(['dot', '-Txdot', input],
+      universal_newlines=True)
+
+    # find the lines containing _ldraw_ attributes
+    ldraw = re.findall(r'^\s*_ldraw_\s*=(.*?)$', output, re.MULTILINE)
+    assert ldraw is not None, 'no _ldraw_ attributes in graph'
+
+    # one of these should contain the label correctly escaped
+    assert any(r'hello \\\" world' in l for l in ldraw), \
+      'unexpected ldraw contents'
+
 def test_1436():
     '''
     test a segfault from https://gitlab.com/graphviz/graphviz/-/issues/1436 has