Skip to content

String escaping needed in nodes and labeled edges #5

@nedtwigg

Description

@nedtwigg

Node names are inserted into the dot file without quotes or escaping of any kind.

Labeled edges are inserted into the dot file with quotes, but no escaping beyond that (e.g. a double quote in a labeled edge will break things).

This was easy to workaround like so:

class MyNodeType {
  fun dotSafeIfWithinQuotes() = toString().replace("\"", "\\\"").replace("\n", "\\n")
  fun dotSafe(): String = "\"${dotSafeIfWithinQuotes()}\""
}
...
digraph {
  source.dotSafe() - target.dotSafe() + { this.label = edge.dotSafeIfWithinQuotes() }
}

Ideally strings would be automatically escaped correctly, but nbd, and fixing this would break any workarounds people are using now.

Great library that solved my problem quickly, thanks very much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions