Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/erb/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def format_attributes(tag_name, attrs, tag_closing)
name, value = attr.split('=', 2)

if value.nil?
attr_html << indented("#{name}")
attr_html << (within_line_width ? " #{name}" : indented("#{name}"))
next
end

if /\A#{UNQUOTED_VALUE}\z/o.match?(value)
attr_html << indented("#{name}=\"#{value}\"")
attr_html << (within_line_width ? " #{name}=\"#{value}\"" : indented("#{name}=\"#{value}\""))
next
end

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/attributes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
data-short-url="//test.com/?q=v"
data-long-url="https://google.ca/this-is-a-long-url-with-a-query-string?query=something"
data-long-url-single='https://google.ca/this-is-a-long-url-with-a-query-string?query=something'>
<input type=text class="text-sm" hidden />
<input name="very-long-name-should-break-because-of-longer-than-width" type=text class="text-sm" hidden />
7 changes: 7 additions & 0 deletions test/fixtures/attributes.html.expected.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
data-long-url="https://google.ca/this-is-a-long-url-with-a-query-string?query=something"
data-long-url-single='https://google.ca/this-is-a-long-url-with-a-query-string?query=something'
>
<input type="text" class="text-sm" hidden/>
<input
name="very-long-name-should-break-because-of-longer-than-width"
type="text"
class="text-sm"
hidden
/>