Skip to content

Commit

Permalink
Fix an attribute serialization bug when using nested attributes with …
Browse files Browse the repository at this point in the history
…symbol values
  • Loading branch information
willcosgrove committed Sep 7, 2024
1 parent ceffded commit 425e555
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def __nested_attributes__(attributes, base_name, buffer = +"")
when String
buffer << " " << base_name << name << '="' << v.gsub('"', "&quot;") << '"'
when Symbol
buffer << " " << name << '="' << v.name.tr("_", "-").gsub('"', "&quot;") << '"'
buffer << " " << base_name << name << '="' << v.name.tr("_", "-").gsub('"', "&quot;") << '"'
when Integer, Float
buffer << " " << base_name << name << '="' << v.to_s << '"'
when Hash
Expand Down
10 changes: 10 additions & 0 deletions quickdraw/sgml/attributes.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@

expect(example.call) == %(<#{tag} style="color:red;font-weight:bold;">content</#{tag}>)
end

test "<#{tag}> with data attributes" do
example = Class.new(Phlex::HTML) do
define_method :view_template do
__send__(method_name, data: { controller: "foo", turbo_action: :delete }) { "content" }
end
end

expect(example.call) == %(<#{tag} data-controller="foo" data-turbo-action="delete">content</#{tag}>)
end
end

0 comments on commit 425e555

Please sign in to comment.