From 871d15dac727e1e00cce9c943589ec1b90142126 Mon Sep 17 00:00:00 2001 From: Xavier Delamotte Date: Sat, 6 Jan 2024 14:44:58 +0000 Subject: [PATCH] Format unquotted attributes Fix #40 --- lib/erb/formatter.rb | 4 ++++ test/fixtures/attributes.html.erb | 8 ++++++++ test/fixtures/attributes.html.expected.erb | 7 +++++++ 3 files changed, 19 insertions(+) create mode 100644 test/fixtures/attributes.html.erb create mode 100644 test/fixtures/attributes.html.expected.erb diff --git a/lib/erb/formatter.rb b/lib/erb/formatter.rb index 193620c..fff8be1 100644 --- a/lib/erb/formatter.rb +++ b/lib/erb/formatter.rb @@ -136,6 +136,10 @@ def format_attributes(tag_name, attrs, tag_closing) attrs.scan(ATTR).flatten.each do |attr| attr.strip! name, value = attr.split('=', 2) + if UNQUOTED_ATTR =~ attr + attr_html << indented("#{name}=\"#{value}\"") + next + end if value.nil? attr_html << indented("#{name}") diff --git a/test/fixtures/attributes.html.erb b/test/fixtures/attributes.html.erb new file mode 100644 index 0000000..68c1352 --- /dev/null +++ b/test/fixtures/attributes.html.erb @@ -0,0 +1,8 @@ +Responsive Image diff --git a/test/fixtures/attributes.html.expected.erb b/test/fixtures/attributes.html.expected.erb new file mode 100644 index 0000000..b2c55ff --- /dev/null +++ b/test/fixtures/attributes.html.expected.erb @@ -0,0 +1,7 @@ +Responsive Image