lib/padrino-helpers/format_helpers.rb in padrino-helpers-0.11.0 vs lib/padrino-helpers/format_helpers.rb in padrino-helpers-0.11.1

- old
+ new

@@ -17,11 +17,11 @@ # escape_html("<b>Hey<b>") => "&lt;b&gt;Hey&lt;b;gt;" # h("Me & Bob") => "Me &amp; Bob" # # @api public def escape_html(text) - Rack::Utils.escape_html(text) + Rack::Utils.escape_html(text).html_safe end alias h escape_html alias sanitize_html escape_html ## @@ -39,12 +39,12 @@ # h!("Me & Bob") => "Me &amp; Bob" # h!("", "Whoops") => "Whoops" # # @api public def h!(text, blank_text = '&nbsp;') - return blank_text if text.nil? || text.empty? - h text + return blank_text.html_safe if text.nil? || text.empty? + h(text) end ## # Strips all HTML tags from the html # @@ -81,16 +81,17 @@ # # @api public def simple_format(text, options={}) t = options.delete(:tag) || :p start_tag = tag(t, options, true) - text = text.to_s.dup + text = escape_html(text.to_s.dup) text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br text.insert 0, start_tag text << "</#{t}>" + text.html_safe end ## # Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1, # otherwise it will use the Inflector to determine the plural form @@ -372,10 +373,12 @@ # # @api public def js_escape_html(html_content) return '' unless html_content javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" } - html_content.gsub(/(\\|<\/|\r\n|[\n\r"'])/){|m| javascript_mapping[m]} + escaped_content = html_content.gsub(/(\\|<\/|\r\n|[\n\r"'])/){ |m| javascript_mapping[m] } + escaped_content = escaped_content.html_safe if html_content.html_safe? + escaped_content end alias :escape_javascript :js_escape_html end # FormatHelpers end # Helpers end # Padrino