diff --git a/lib/erb/formatter.rb b/lib/erb/formatter.rb index 537ddd2..b14b375 100644 --- a/lib/erb/formatter.rb +++ b/lib/erb/formatter.rb @@ -26,6 +26,8 @@ def format(q) class Error < StandardError; end + SPACES = /\s+/m + # https://stackoverflow.com/a/317081 ATTR_NAME = %r{[^\r\n\t\f\v= '"<>]*[^\r\n\t\f\v= '"<>/]} # not ending with a slash UNQUOTED_VALUE = %r{[^<>'"\s]+} @@ -147,7 +149,7 @@ def format_attributes(tag_name, attrs, tag_closing) next end - value_parts = value[1...-1].strip.split(/\s+/) + value_parts = value[1...-1].strip.split(SPACES) value_parts.sort_by!(&@css_class_sorter) if name == 'class' && @css_class_sorter full_attr = "#{name}=#{value[0]}#{value_parts.join(" ")}#{value[-1]}" @@ -232,7 +234,7 @@ def format_text(text) return if text.match?(/\A\s*\z/m) # empty - text = text.gsub(/\s+/m, ' ').strip + text = text.gsub(SPACES, ' ').strip offset = indented("").size # Restore full line width if there are less than 40 columns available