Skip to content

Commit

Permalink
Merge pull request #88 from Shopify/fix-mermaid-renderer
Browse files Browse the repository at this point in the history
Fix a character escape issue with the Mermaid formatter that could result in invalid syntax.
  • Loading branch information
nirvdrum authored Mar 21, 2024
2 parents 623cd0a + fa324b6 commit bf0a2a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ New Features:

Bug Fixes:

* Fixed an invalid method call in `bgv2json` (#82, @nirvdrum).
* Fixed an invalid method call in `bgv2json` (#79, @nirvdrum).
* Fixed a character escape issue with the Mermaid formatter that could result in invalid syntax (#87, @nirvdrum).

Changes:

Expand All @@ -28,7 +29,7 @@ Changes:
* Removed hidden nodes from the `describe` command output (#66, @chrisseaton).
* Improved the `describe` command output to ignore hidden nodes (@chrisseaton).
* Added more “triggers” to detect if we’re looking at Graal or Truffle graphs (as opposed to regular JVM graphs) (@chrisseaton).
* Support simplifying more allocation node classes (#73, @nirvdrum).
* Support simplifying more allocation node classes (#67, @nirvdrum).


# 0.14
Expand Down
2 changes: 1 addition & 1 deletion lib/seafoam/mermaid_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def output_node(indent, id, attrs)
when "diamond"
shape = ["{{", "}}"]
end
@stream.puts "#{indent}#{id}#{shape[0]}#{attrs[:label].inspect}#{shape[1]}"
@stream.puts "#{indent}#{id}#{shape[0]}#{attrs[:label].gsub('"', "#quot;").inspect}#{shape[1]}"
@stream.puts "#{indent}style #{id} fill:#{attrs[:fillcolor]},stroke:#{attrs[:color]},color:#{attrs[:fontcolor]};"
end

Expand Down
15 changes: 15 additions & 0 deletions spec/seafoam/mermaid_write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,20 @@
end
end
end

it "escapes quotes in labels" do
attrs = {
color: "black",
fillcolor: "#f9f9f9",
fontcolor: "#1a1919",
fontname: "Arial",
label: "\"abc\"",
shape: "rectangle",
style: "filled",
}

@writer.send(:output_node, "", "node0", attrs)
expect(@stream.string).to(include("node0(\"#quot;abc#quot;\")"))
end
end
end

0 comments on commit bf0a2a9

Please sign in to comment.