Skip to content

Commit

Permalink
Fix a character escape issue with the Mermaid formatter that could re…
Browse files Browse the repository at this point in the history
…sult in invalid syntax.
  • Loading branch information
nirvdrum committed Mar 21, 2024
1 parent 623cd0a commit 755e780
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ New Features:
Bug Fixes:

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

Changes:

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 755e780

Please sign in to comment.