From 425e555dd6b3f9a064dea7c5dbe36c76188f9295 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Sat, 7 Sep 2024 11:02:44 -0500 Subject: [PATCH] Fix an attribute serialization bug when using nested attributes with symbol values --- lib/phlex/sgml.rb | 2 +- quickdraw/sgml/attributes.test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index 82418653..3f7581f8 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -514,7 +514,7 @@ def __nested_attributes__(attributes, base_name, buffer = +"") when String buffer << " " << base_name << name << '="' << v.gsub('"', """) << '"' when Symbol - buffer << " " << name << '="' << v.name.tr("_", "-").gsub('"', """) << '"' + buffer << " " << base_name << name << '="' << v.name.tr("_", "-").gsub('"', """) << '"' when Integer, Float buffer << " " << base_name << name << '="' << v.to_s << '"' when Hash diff --git a/quickdraw/sgml/attributes.test.rb b/quickdraw/sgml/attributes.test.rb index be922486..1c77a779 100644 --- a/quickdraw/sgml/attributes.test.rb +++ b/quickdraw/sgml/attributes.test.rb @@ -40,4 +40,14 @@ expect(example.call) == %(<#{tag} style="color:red;font-weight:bold;">content) 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) + end end