diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2022-11-04 09:46:23 -0700 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-11-04 16:46:29 +0000 |
commit | b169d78c882efdb4a3da6077f6d723f65ded6f15 (patch) | |
tree | 1c9ca5641a43358e2cc4f1a554c0e6af5db924e4 | |
parent | 13395757fa7fe0abee3a260d5669baec2dc2e0fc (diff) | |
download | ruby-b169d78c882efdb4a3da6077f6d723f65ded6f15.tar.gz |
[ruby/erb] Avoid using prepend + super for fallback
(https://github.com/ruby/erb/pull/28)
`prepend` is prioritized more than ActiveSupport's monkey-patch, but the
monkey-patch needs to work.
https://github.com/ruby/erb/commit/611de5a865
-rw-r--r-- | ext/erb/erb.c | 12 | ||||
-rw-r--r-- | lib/erb.rb | 20 |
2 files changed, 15 insertions, 17 deletions
diff --git a/ext/erb/erb.c b/ext/erb/erb.c index 4adab8ad33..c90f77f7b1 100644 --- a/ext/erb/erb.c +++ b/ext/erb/erb.c @@ -1,7 +1,8 @@ #include "ruby.h" #include "ruby/encoding.h" -static VALUE rb_cERB, rb_mEscape; +static VALUE rb_cERB, rb_mUtil, rb_cCGI; +static ID id_escapeHTML; #define HTML_ESCAPE_MAX_LEN 6 @@ -76,7 +77,7 @@ erb_escape_html(VALUE self, VALUE str) return optimized_escape_html(str); } else { - return rb_call_super(1, &str); + return rb_funcall(rb_cCGI, id_escapeHTML, 1, str); } } @@ -84,6 +85,9 @@ void Init_erb(void) { rb_cERB = rb_define_class("ERB", rb_cObject); - rb_mEscape = rb_define_module_under(rb_cERB, "Escape"); - rb_define_method(rb_mEscape, "html_escape", erb_escape_html, 1); + rb_mUtil = rb_define_module_under(rb_cERB, "Util"); + rb_define_method(rb_mUtil, "html_escape", erb_escape_html, 1); + + rb_cCGI = rb_define_class("CGI", rb_cObject); + id_escapeHTML = rb_intern("escapeHTML"); } diff --git a/lib/erb.rb b/lib/erb.rb index c588ae1a65..48dcca71aa 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -998,20 +998,14 @@ class ERB # # is a > 0 & a < 10? # - def html_escape(s) - CGI.escapeHTML(s.to_s) + begin + # ERB::Util.html_escape + require 'erb.so' + rescue LoadError + def html_escape(s) + CGI.escapeHTML(s.to_s) + end end - end - - begin - require 'erb.so' - rescue LoadError - else - private_constant :Escape - Util.prepend(Escape) - end - - module Util alias h html_escape module_function :h module_function :html_escape |