lib/roda/plugins/h.rb in roda-2.29.0 vs lib/roda/plugins/h.rb in roda-3.0.0

- old
+ new

@@ -15,21 +15,25 @@ # end module H begin require 'cgi/escape' unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1 + # :nocov: CGI = Object.new CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util) + # :nocov: end module InstanceMethods # HTML escape the input and return the escaped version. def h(string) CGI.escapeHTML(string.to_s) end end rescue LoadError + # :nocov: + # A Hash of entities and their escaped equivalents, # to be escaped by h(). ESCAPE_HTML = { "&" => "&amp;".freeze, "<" => "&lt;".freeze, @@ -44,9 +48,10 @@ module InstanceMethods def h(string) string.to_s.gsub(ESCAPE_HTML_PATTERN){|c| ESCAPE_HTML[c] } end end + # :nocov: end end register_plugin(:h, H) end