]> granicus.if.org Git - graphviz/commitdiff
fix: unescaped backslashes in edge labels in xdot output
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 21 Jul 2020 00:54:38 +0000 (17:54 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 21 Jul 2020 00:55:25 +0000 (17:55 -0700)
A variant of #165.

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

index f6b29ea02c92cba253ac88b966d2e690d963aa79..a2d9b8f1b5b95938863226fe3ea3009c103523f3 100644 (file)
@@ -304,7 +304,7 @@ static void xdot_end_edge(GVJ_t* job)
     if (agxblen(xbufs[EMIT_HDRAW]))
        agxset(e, xd->h_draw, agxbuse(xbufs[EMIT_HDRAW]));
     if (agxblen(xbufs[EMIT_ELABEL]))
-       agxset(e, xd->e_l_draw,agxbuse(xbufs[EMIT_ELABEL]));
+       put_escaping_backslashes(e, xd->e_l_draw, agxbuse(xbufs[EMIT_ELABEL]));
     if (agxblen(xbufs[EMIT_TLABEL]))
        agxset(e, xd->tl_draw, agxbuse(xbufs[EMIT_TLABEL]));
     if (agxblen(xbufs[EMIT_HLABEL]))
diff --git a/rtest/165_2.dot b/rtest/165_2.dot
new file mode 100644 (file)
index 0000000..677ccbf
--- /dev/null
@@ -0,0 +1,4 @@
+// see test_regression.py:test_165_2()
+digraph {
+  a -> b [label="hello \\\" world"];
+}
index 7444354549d84998cd367345e3e8a288b628166b..98f6f1c0fd356184fa24e5047e0b6ce2816f5293 100644 (file)
@@ -55,6 +55,28 @@ def test_165():
     assert r'hello \\\" world' in ldraw.group('value'), \
       'unexpected ldraw contents'
 
+def test_165_2():
+    '''
+    variant of test_165() that checks a similar problem for edges
+    https://gitlab.com/graphviz/graphviz/-/issues/165
+    '''
+
+    # locate our associated test case in this directory
+    input = os.path.join(os.path.dirname(__file__), '165_2.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