microsoft/automatic-graph-layout

Export to SVG incorrectly exports some characters.

wvdvegt opened this issue · 2 comments

When I export a graph containing certain characters , the SVG won't load/display in for example Microsoft Edge.

See #351 for screenshots of the text used.

In the LabelTest the following characters are not exported properly:

  • '&' Should be exported as '&' as SVG is an xml based format.
  • '<' Should be exported as '<'.
  • leading spaces (use for simple indent) should be exported as '&# 160;' (as '&nbsp;' fails with an xml error as well).

FYI I was able to correct the '&' and '<' issue by supplying a nodeSanitizer to the SvgGraphWriter.Write() method.

Func<string, string> nodeSanitizer = s =>
{
return s
	.Replace("&", "&amp;")
	.Replace("<", "&lt;")
	.Replace(" ", "&#160;");
};

Should your change be a part of the default sanitizer? If so, please create a pull request.

Not confortable enough with the code to make such changes & pull requests.

I was unware there was a default sanitizer at all. Did you mean the code in WriteLabelText()?