diff --git a/jlm/util/GraphWriter.cpp b/jlm/util/GraphWriter.cpp index 0f941ff3d..af28c556d 100644 --- a/jlm/util/GraphWriter.cpp +++ b/jlm/util/GraphWriter.cpp @@ -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(&value)) { if (format == AttributeOutputFormat::SpaceSeparatedList) PrintIdentifierSafe(out, *string); else - { - out << '"'; PrintStringAsHtmlText(out, *string); - out << '"'; - } } else if (auto graphElement = std::get_if(&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(&value)) @@ -291,6 +289,8 @@ GraphElement::OutputAttributes(std::ostream & out, AttributeOutputFormat format) out << "ptr" << ptr; } } + if (format == AttributeOutputFormat::HTMLAttributes) + out << '"'; // Closing quote out << " "; } } diff --git a/tests/jlm/util/TestGraphWriter.cpp b/tests/jlm/util/TestGraphWriter.cpp index e0a9cf9f8..8260b47e5 100644 --- a/tests/jlm/util/TestGraphWriter.cpp +++ b/tests/jlm/util/TestGraphWriter.cpp @@ -62,7 +62,7 @@ TestGraphElement() graph.OutputAttributes(out, AttributeOutputFormat::HTMLAttributes); attributes = out.str(); assert(StringContains(attributes, "color=\""brown"\"")); - assert(StringContains(attributes, "another-graph=graph0")); + assert(StringContains(attributes, "another-graph=\"graph0\"")); } static void