8000 Let Haml::Util.escape_html use ERB::Escape by k0kubun · Pull Request #1145 · haml/haml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Let Haml::Util.escape_html use ERB::Escape #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions ext/haml/haml.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ escape_attribute(VALUE escape_attrs, VALUE str)
}
}

static VALUE
rb_escape_html(RB_UNUSED_VAR(VALUE self), VALUE value)
{
return escape_html(to_s(value));
}

static VALUE
haml_build_id(VALUE escape_attrs, VALUE values)
{
Expand Down Expand Up @@ -504,14 +498,12 @@ rb_haml_build(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
void
Init_haml(void)
{
VALUE mHaml, mUtil;
VALUE mHaml;

mHaml = rb_define_module("Haml");
mObjectRef = rb_define_module_under(mHaml, "ObjectRef");
mUtil = rb_define_module_under(mHaml, "Util");
mAttributeBuilder = rb_define_module_under(mHaml, "AttributeBuilder");

rb_define_singleton_method(mUtil, "escape_html", rb_escape_html, 1);
rb_define_singleton_method(mAttributeBuilder, "build", rb_haml_build, -1);
rb_define_singleton_method(mAttributeBuilder, "build_id", rb_haml_build_id, -1);
rb_define_singleton_method(mAttributeBuilder, "build_class", rb_haml_build_class, -1);
Expand Down
9 changes: 5 additions & 4 deletions lib/haml/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ module Haml
module Util
extend self

# For JRuby, TruffleRuby, and Wasm, fallback to Ruby implementation.
if /java|wasm/ === RUBY_PLATFORM || RUBY_ENGINE == 'truffleruby'
begin # Ruby 3.2+ or ERB 4+
require 'erb/escape'

define_singleton_method(:escape_html, ERB::Escape.instance_method(:html_escape))
rescue LoadError
require 'cgi/escape'

def self.escape_html(html)
CGI.escapeHTML(html.to_s)
end
else
require 'haml/haml' # Haml::Util.escape_html
end

# TODO: Remove unescape_interpolation's workaround and get rid of `respond_to?`.
Expand Down
0