1
- # Use module_eval so we crash when ERB::Util has not yet been loaded.
2
- if defined? ( ActiveSupport ::CoreExt ::ERBUtil ) && ERB ::Util . is_a? ( ActiveSupport ::CoreExt ::ERBUtil )
3
- # Rails 7.1+
1
+ if ERB ::Util . private_method_defined? :unwrapped_html_escape
2
+ # Rails 4.2 +
4
3
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/erb/util.rb
5
4
module ERBUtilExt
6
5
def html_escape_once ( s )
@@ -17,51 +16,22 @@ def unwrapped_html_escape(s)
17
16
18
17
else
19
18
ERB ::Util . module_eval do
20
- if private_method_defined? :unwrapped_html_escape
21
- # Rails 4.2 - 7.0
22
- # patch ERB::Util#unwrapped_html_escape
23
- def unwrapped_html_escape_with_escaping_angular_expressions ( s )
24
- unwrapped_html_escape_without_escaping_angular_expressions ( AngularXss ::Escaper . escape_if_unsafe ( s ) )
25
- end
19
+ # Rails < 4.2
26
20
27
- alias_method :unwrapped_html_escape_without_escaping_angular_expressions , :unwrapped_html_escape
28
- alias_method :unwrapped_html_escape , :unwrapped_html_escape_with_escaping_angular_expressions
29
-
30
- singleton_class . send ( :remove_method , :unwrapped_html_escape )
31
- module_function :unwrapped_html_escape
32
- module_function :unwrapped_html_escape_without_escaping_angular_expressions
33
-
34
- # patch ERB::Util#html_escape_once
35
- def html_escape_once_with_escaping_angular_expressions ( s )
36
- html_escape_once_without_escaping_angular_expressions ( AngularXss ::Escaper . escape_if_unsafe ( s ) )
37
- end
38
-
39
- alias_method :html_escape_once_without_escaping_angular_expressions , :html_escape_once
40
- alias_method :html_escape_once , :html_escape_once_with_escaping_angular_expressions
41
-
42
- singleton_class . send ( :remove_method , :html_escape_once )
43
- module_function :html_escape_once
44
- module_function :html_escape_once_without_escaping_angular_expressions
45
- else
46
- # Rails < 4.2
47
-
48
- def html_escape_with_escaping_angular_expressions ( s )
49
- html_escape_without_escaping_angular_expressions ( AngularXss ::Escaper . escape_if_unsafe ( s ) )
50
- end
51
-
52
- alias_method_chain :html_escape , :escaping_angular_expressions
53
-
54
- # Aliasing twice issues a warning "discarding old...". Remove first to avoid it.
55
- remove_method ( :h )
56
- alias h html_escape
21
+ def html_escape_with_escaping_angular_expressions ( s )
22
+ html_escape_without_escaping_angular_expressions ( AngularXss ::Escaper . escape_if_unsafe ( s ) )
23
+ end
57
24
58
- module_function :h
25
+ alias_method_chain :html_escape , :escaping_angular_expressions
59
26
60
- singleton_class . send ( :remove_method , :html_escape )
61
- module_function :html_escape
62
- module_function :html_escape_without_escaping_angular_expressions
27
+ # Aliasing twice issues a warning "discarding old...". Remove first to avoid it.
28
+ remove_method ( :h )
29
+ alias h html_escape
63
30
64
- end
31
+ module_function :h
65
32
33
+ singleton_class . send ( :remove_method , :html_escape )
34
+ module_function :html_escape
35
+ module_function :html_escape_without_escaping_angular_expressions
66
36
end
67
37
end
0 commit comments