lib/erubi.rb in erubi-1.12.0 vs lib/erubi.rb in erubi-1.13.0
- old
+ new
@@ -1,9 +1,9 @@
# frozen_string_literal: true
module Erubi
- VERSION = '1.12.0'
+ VERSION = '1.13.0'
# :nocov:
if RUBY_VERSION >= '1.9'
RANGE_FIRST = 0
RANGE_LAST = -1
@@ -17,40 +17,37 @@
FREEZE_TEMPLATE_LITERALS = !eval("''").frozen? && RUBY_VERSION >= '2.1'
# :nocov:
begin
require 'erb/escape'
- # :nocov:
- define_singleton_method(:h, ERB::Escape.instance_method(:html_escape))
- # :nocov:
+ define_method(:h, ERB::Escape.instance_method(:html_escape))
+ # :nocov:
rescue LoadError
begin
require 'cgi/escape'
- # :nocov:
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
CGI = Object.new
CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util)
end
- # :nocov:
# Escape characters with their HTML/XML equivalents.
- def self.h(value)
+ def h(value)
CGI.escapeHTML(value.to_s)
end
rescue LoadError
- # :nocov:
ESCAPE_TABLE = {'&' => '&'.freeze, '<' => '<'.freeze, '>' => '>'.freeze, '"' => '"'.freeze, "'" => '''.freeze}.freeze
if RUBY_VERSION >= '1.9'
- def self.h(value)
+ def h(value)
value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)
end
else
- def self.h(value)
+ def h(value)
value.to_s.gsub(/[&<>"']/){|s| ESCAPE_TABLE[s]}
end
end
- # :nocov:
end
end
+ # :nocov:
+ module_function :h
class Engine
# The default regular expression used for scanning.
DEFAULT_REGEXP = /<%(={1,2}|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m