@@ -13,15 +13,15 @@ module SanitizeHelper
13
13
# It also strips href/src attributes with unsafe protocols like
14
14
# <tt>javascript:</tt>, while also protecting against attempts to use Unicode,
15
15
# ASCII, and hex character references to work around these protocol filters.
16
+ # All special characters will be escaped.
16
17
#
17
18
# The default sanitizer is Rails::Html::WhiteListSanitizer. See {Rails HTML
18
19
# Sanitizers}[https://github.com/rails/rails-html-sanitizer] for more information.
19
20
#
20
21
# Custom sanitization rules can also be provided.
21
22
#
22
23
# Please note that sanitizing user-provided text does not guarantee that the
23
- # resulting markup is valid or even well-formed. For example, the output may still
24
- # contain unescaped characters like <tt><</tt>, <tt>></tt>, or <tt>&</tt>.
24
+ # resulting markup is valid or even well-formed.
25
25
#
26
26
# ==== Options
27
27
#
@@ -86,7 +86,7 @@ def sanitize_css(style)
86
86
self . class . white_list_sanitizer . sanitize_css ( style )
87
87
end
88
88
89
- # Strips all HTML tags from +html+, including comments.
89
+ # Strips all HTML tags from +html+, including comments and special characters .
90
90
#
91
91
# strip_tags("Strip <i>these</i> tags!")
92
92
# # => Strip these tags!
@@ -96,8 +96,11 @@ def sanitize_css(style)
96
96
#
97
97
# strip_tags("<div id='top-bar'>Welcome to my website!</div>")
98
98
# # => Welcome to my website!
99
+ #
100
+ # strip_tags("> A quote from Smith & Wesson")
101
+ # # => > A quote from Smith & Wesson
99
102
def strip_tags ( html )
100
- self . class . full_sanitizer . sanitize ( html , encode_special_chars : false )
103
+ self . class . full_sanitizer . sanitize ( html )
101
104
end
102
105
103
106
# Strips all link tags from +html+ leaving just the link text.
@@ -110,6 +113,9 @@ def strip_tags(html)
110
113
#
111
114
# strip_links('Blog: <a href="http://www.myblog.com/" class="nav" target=\"_blank\">Visit</a>.')
112
115
# # => Blog: Visit.
116
+ #
117
+ # strip_links('<<a href="https://example.org">malformed & link</a>')
118
+ # # => <malformed & link
113
119
def strip_links ( html )
114
120
self . class . link_sanitizer . sanitize ( html )
115
121
end
0 commit comments