File tree 2 files changed +18
-10
lines changed 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 1
1
#include "ruby.h"
2
2
#include "ruby/encoding.h"
3
3
4
- static VALUE rb_cERB , rb_mUtil , rb_cCGI ;
4
+ static VALUE rb_cERB , rb_mEscape , rb_cCGI ;
5
5
static ID id_escapeHTML ;
6
6
7
7
#define HTML_ESCAPE_MAX_LEN 6
87
87
Init_escape (void )
88
88
{
89
89
rb_cERB = rb_define_class ("ERB" , rb_cObject );
90
- rb_mUtil = rb_define_module_under (rb_cERB , "Util " );
91
- rb_define_module_function (rb_mUtil , "html_escape" , erb_escape_html , 1 );
90
+ rb_mEscape = rb_define_module_under (rb_cERB , "Escape " );
91
+ rb_define_module_function (rb_mEscape , "html_escape" , erb_escape_html , 1 );
92
92
93
93
rb_cCGI = rb_define_class ("CGI" , rb_cObject );
94
94
id_escapeHTML = rb_intern ("escapeHTML" );
Original file line number Diff line number Diff line change
1
+ #--
2
+ # ERB::Escape
3
+ #
4
+ # A subset of ERB::Util. Unlike ERB::Util#html_escape, we expect/hope
5
+ # Rails will not monkey-patch ERB::Escape#html_escape.
1
6
begin
2
- # ERB::Util.html_escape
3
7
require 'erb/escape'
4
8
rescue LoadError # JRuby can't load .so
5
9
end
10
+ unless defined? ( ERB ::Escape ) # JRuby
11
+ module ERB ::Escape
12
+ def html_escape ( s )
13
+ CGI . escapeHTML ( s . to_s )
14
+ end
15
+ module_function :html_escape
16
+ end
17
+ end
6
18
7
19
#--
8
20
# ERB::Util
@@ -21,12 +33,8 @@ module ERB::Util
21
33
#
22
34
# is a > 0 & a < 10?
23
35
#
24
- unless defined? ( ERB ::Util . html_escape ) # for JRuby
25
- def html_escape ( s )
26
- CGI . escapeHTML ( s . to_s )
27
- end
28
- module_function :html_escape
29
- end
36
+ include ERB ::Escape # html_escape
37
+ module_function :html_escape
30
38
alias h html_escape
31
39
module_function :h
32
40
You can’t perform that action at this time.
0 commit comments