Skip to content

Commit

Permalink
Fix bug with spaces in dynamic argument
Browse files Browse the repository at this point in the history
Fail scenario:
> echo '<span class="<%= "active" if condition %>"></span>' | html2haml -e
gets:
> %span{:class => "active" if condition}
  • Loading branch information
ffloyd committed Oct 4, 2013
1 parent 3ff5b24 commit 96676c4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/html2haml/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,26 @@ def dynamic_attributes
full_match = nil
ruby_value = value.to_s.gsub(%r{<haml_loud>\s*(.+?)\s*</haml_loud>}) do
full_match = $`.empty? && $'.empty?
CGI.unescapeHTML(full_match ? $1: "\#{#{$1}}")
content = $1
no_spaces = (content =~ /\s/).nil?
result = if full_match
if no_spaces
# situation like attr="<%= blabla %>"
content
else
if content =~ %r{\A\"([^\"]|(\"\")|(\\\")|(\#\{.+\}))*\"\z}
# just a string, maybe with interpolation
content
else
# situation like attr="<%= 'active' if some_var %>"
"\"\#{#{content}}\""
end
end
else
# we need to intrapolate because of we are in the middle of text (attr = "bla bla <%= bla %> bla" )
"\#{#{content}}"
end
CGI.unescapeHTML(result)
end
if ruby_value == value
[nil, nil]
Expand Down

0 comments on commit 96676c4

Please sign in to comment.