Skip to content

Commit

Permalink
Fix non-quoted html attributes in dot output (#414)
Browse files Browse the repository at this point in the history
Apologies, but I realized I had mis-read the dot language spec. Unlike
in HTML/XML, all attribute values must always be quoted. This PR fixes
this. It is part of #308

Co-authored-by: Nico Reissmann <[email protected]>
  • Loading branch information
haved and phate authored Mar 1, 2024
1 parent f4e2d28 commit 357b080
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions jlm/util/GraphWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,18 @@ GraphElement::OutputAttributes(std::ostream & out, AttributeOutputFormat format)
JLM_UNREACHABLE("Unknown AttributeOutputFormat");

out << "=";
if (format == AttributeOutputFormat::HTMLAttributes)
out << '"'; // HTML attributes must be quoted

if (auto string = std::get_if<std::string>(&value))
{
if (format == AttributeOutputFormat::SpaceSeparatedList)
PrintIdentifierSafe(out, *string);
else
{
out << '"';
PrintStringAsHtmlText(out, *string);
out << '"';
}
}
else if (auto graphElement = std::get_if<const GraphElement *>(&value))
{
// HTML allows unquoted attribute values when they are single words with no special characters
out << (*graphElement)->GetFullId();
}
else if (auto ptr = std::get_if<uintptr_t>(&value))
Expand All @@ -291,6 +289,8 @@ GraphElement::OutputAttributes(std::ostream & out, AttributeOutputFormat format)
out << "ptr" << ptr;
}
}
if (format == AttributeOutputFormat::HTMLAttributes)
out << '"'; // Closing quote
out << " ";
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/jlm/util/TestGraphWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TestGraphElement()
graph.OutputAttributes(out, AttributeOutputFormat::HTMLAttributes);
attributes = out.str();
assert(StringContains(attributes, "color=\"&quot;brown&quot;\""));
assert(StringContains(attributes, "another-graph=graph0"));
assert(StringContains(attributes, "another-graph=\"graph0\""));
}

static void
Expand Down

0 comments on commit 357b080

Please sign in to comment.