Admin message

Please use the issue tracker only to report bugs (i.e. errors in the library that need to be fixed) or feature requests.

Please check if the current git version also has the same problem. An easy way to do this is to use google colab!

For questions about how to compile, install or use the library, please use instead the web forum at https://forum.skewed.de/c/graph-tool.


(If unsure, use the forum first.)


IMPORTANT: When opening new issues, please fill out the required information listed in the issue template!

Writing DOT files does not quote ID strings correctly

Bug reports:

Please follow the general troubleshooting steps first:

  • Are you running the latest graph-tool version?
  • Do you observe the problem with the current git version?
  • Are you using Macports or Homebrew? If yes, please submit an issue there instead: https://github.com/Homebrew/brew/issues and https://trac.macports.org/newticket
  • Did you compile graph-tool manually?
  • If you answered yes above, did you use the exact same compiler to build graph-tool, boost-python and Python?

Problem

I have a DOT file with names as node_ids which contain dashes ('-'). These names are quoted (because of the dashes). Loading such a file works fine, however, when saving the graph again to DOT format, the quotes are gone:

echo 'digraph G { "name-with-dashes"; }' | python3 -c 'import io; import sys; import graph_tool.all as gt; output = io.BytesIO(); g = gt.load_graph(sys.stdin, fmt="dot"); g.save(output, fmt="dot"); print(output.getvalue().decode())'

Output:

digraph G {
name-with-dashes;
}

According to the DOT file specification (http://www.graphviz.org/doc/info/lang.html) a node_id (or just ID) may include a dash '-' either if it is numerical or quoted. So the resulting DOT file does not comply with the specification.

This becomes clear when trying to load the above DOT file output again in graph-tool:

echo 'digraph G { "name-with-dashes"; }' | python3 -c 'import io; import sys; import graph_tool.all as gt; output = io.BytesIO(); g = gt.load_graph(sys.stdin, fmt="dot"); g.save(output, fmt="dot"); print(output.getvalue().decode())' |  python3 -c 'import sys; import graph_tool.all as gt; g = gt.load_graph(sys.stdin, fmt="dot")'

which fails with an error message complaining about the unquoted dashes (as expected):

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/graph_tool/__init__.py", line 2936, in load_graph
    g.load(file_name, fmt, ignore_vp, ignore_ep, ignore_gp)
  File "/usr/lib/python3.6/site-packages/graph_tool/__init__.py", line 2485, in load
    ignore_vp, ignore_ep, ignore_gp)
RuntimeError: Invalid character (char is '-')

Suggested fix

When writing DOT files: Check vertex_name for illegal characters and quote the whole name if necessary.

System Information:

  • OS: Archlinux 4.16.5-1-ARCH
  • Python 3.6.5
  • gcc 7.3.1
  • boost 1.66.0
Assignee Loading
Time tracking Loading