Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit c85a1d6

Browse files
committed
Use #prepend for HAML patches
1 parent efbf0c0 commit c85a1d6

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/angular_xss/erb.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if ERB::Util.private_method_defined? :unwrapped_html_escape
2-
# Rails 4.2 +
2+
# Rails 4.2+
33
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/erb/util.rb
44
module ERBUtilExt
55
def html_escape_once(s)
@@ -9,7 +9,7 @@ def html_escape_once(s)
99
def unwrapped_html_escape(s)
1010
super(AngularXss::Escaper.escape_if_unsafe(s))
1111
end
12-
# Note that html_escape() and h() are passively fixed as they are calling the new methods.
12+
# Note that html_escape() and h() are passively fixed as they are calling the two methods above
1313
end
1414
ERB::Util.prepend ERBUtilExt
1515
ERB::Util.singleton_class.prepend ERBUtilExt

lib/angular_xss/haml.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@ def html_escape_with_escaping_angular_expressions(s)
1414
# Haml 5.0 and 5.1 fall back to erb
1515
elsif haml_version < Gem::Version.new(6)
1616
# HAML 5.2+
17-
Haml::Helpers.module_eval do
18-
def html_escape_without_haml_xss_with_escaping_angular_expressions(s)
19-
html_escape_without_haml_xss_without_escaping_angular_expressions(AngularXss::Escaper.escape_if_unsafe(s))
17+
module HTMLEscapeWithoutHAMLWithAngularXSS
18+
def html_escape_without_haml_xss(html)
19+
super(AngularXss::Escaper.escape_if_unsafe(html))
2020
end
21-
22-
alias_method :html_escape_without_haml_xss_without_escaping_angular_expressions, :html_escape_without_haml_xss
23-
alias_method :html_escape_without_haml_xss, :html_escape_without_haml_xss_with_escaping_angular_expressions
2421
end
22+
23+
Haml::Helpers.singleton_class.prepend HTMLEscapeWithoutHAMLWithAngularXSS
2524
else
2625
# Haml 6+
2726
# It ditched most of is own helpers in favor of Haml::Util.escape_html
2827
# https://github.com/haml/haml/blob/main/CHANGELOG.md#600
2928
# https://github.com/haml/haml/compare/v5.2.2...v6.3.0
3029
# https://github.com/haml/haml/blob/v6.3.0/lib/haml/util.rb
3130

32-
module HamlUtilExt
31+
module EscapeHTMLWithAngularXSS
3332
def escape_html(html)
3433
super(AngularXss::Escaper.escape_if_unsafe(html))
3534
end
3635
end
3736

38-
Haml::Util.singleton_class.prepend HamlUtilExt
37+
Haml::Util.singleton_class.prepend EscapeHTMLWithAngularXSS
3938
end

0 commit comments

Comments
 (0)