Skip to content

Commit

Permalink
Skip formatting unquotted attributes
Browse files Browse the repository at this point in the history
Fix #40
  • Loading branch information
x4d3 committed Jan 6, 2024
1 parent 183125e commit 88e218c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/erb/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def format_attributes(tag_name, attrs, tag_closing)

attrs.scan(ATTR).flatten.each do |attr|
attr.strip!
if UNQUOTED_ATTR =~ attr
attr_html << indented(attr)
next
end
name, value = attr.split('=', 2)

if value.nil?
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/attributes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<img src="image.jpg" alt="Responsive Image"
srcset="image-480w.jpg 480w,
image-800w.jpg 800w,
image-1200w.jpg 1200w"
sizes="(max-width: 600px) 480px,
(max-width: 1000px) 800px,
1200px"
data-autocomplete-min-length-value=2>
7 changes: 7 additions & 0 deletions test/fixtures/attributes.html.expected.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<img
src="image.jpg"
alt="Responsive Image"
srcset="image-480w.jpg 480w, image-800w.jpg 800w, image-1200w.jpg 1200w"
sizes="(max-width: 600px) 480px, (max-width: 1000px) 800px, 1200px"
data-autocomplete-min-length-value=2
>

0 comments on commit 88e218c

Please sign in to comment.