[ruby/erb] Define ERB::Escape module
(https://github.com/ruby/erb/pull/38) Close #32
This commit is contained in:
parent
15be9ecbcc
commit
574896a0ce
@ -1,7 +1,7 @@
|
|||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
|
|
||||||
static VALUE rb_cERB, rb_mUtil, rb_cCGI;
|
static VALUE rb_cERB, rb_mEscape, rb_cCGI;
|
||||||
static ID id_escapeHTML;
|
static ID id_escapeHTML;
|
||||||
|
|
||||||
#define HTML_ESCAPE_MAX_LEN 6
|
#define HTML_ESCAPE_MAX_LEN 6
|
||||||
@ -87,8 +87,8 @@ void
|
|||||||
Init_escape(void)
|
Init_escape(void)
|
||||||
{
|
{
|
||||||
rb_cERB = rb_define_class("ERB", rb_cObject);
|
rb_cERB = rb_define_class("ERB", rb_cObject);
|
||||||
rb_mUtil = rb_define_module_under(rb_cERB, "Util");
|
rb_mEscape = rb_define_module_under(rb_cERB, "Escape");
|
||||||
rb_define_module_function(rb_mUtil, "html_escape", erb_escape_html, 1);
|
rb_define_module_function(rb_mEscape, "html_escape", erb_escape_html, 1);
|
||||||
|
|
||||||
rb_cCGI = rb_define_class("CGI", rb_cObject);
|
rb_cCGI = rb_define_class("CGI", rb_cObject);
|
||||||
id_escapeHTML = rb_intern("escapeHTML");
|
id_escapeHTML = rb_intern("escapeHTML");
|
||||||
|
@ -1,8 +1,20 @@
|
|||||||
|
#--
|
||||||
|
# ERB::Escape
|
||||||
|
#
|
||||||
|
# A subset of ERB::Util. Unlike ERB::Util#html_escape, we expect/hope
|
||||||
|
# Rails will not monkey-patch ERB::Escape#html_escape.
|
||||||
begin
|
begin
|
||||||
# ERB::Util.html_escape
|
|
||||||
require 'erb/escape'
|
require 'erb/escape'
|
||||||
rescue LoadError # JRuby can't load .so
|
rescue LoadError # JRuby can't load .so
|
||||||
end
|
end
|
||||||
|
unless defined?(ERB::Escape) # JRuby
|
||||||
|
module ERB::Escape
|
||||||
|
def html_escape(s)
|
||||||
|
CGI.escapeHTML(s.to_s)
|
||||||
|
end
|
||||||
|
module_function :html_escape
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#--
|
#--
|
||||||
# ERB::Util
|
# ERB::Util
|
||||||
@ -21,12 +33,8 @@ module ERB::Util
|
|||||||
#
|
#
|
||||||
# is a > 0 & a < 10?
|
# is a > 0 & a < 10?
|
||||||
#
|
#
|
||||||
unless defined?(ERB::Util.html_escape) # for JRuby
|
include ERB::Escape # html_escape
|
||||||
def html_escape(s)
|
module_function :html_escape
|
||||||
CGI.escapeHTML(s.to_s)
|
|
||||||
end
|
|
||||||
module_function :html_escape
|
|
||||||
end
|
|
||||||
alias h html_escape
|
alias h html_escape
|
||||||
module_function :h
|
module_function :h
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user