diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-02-27 18:13:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-27 18:13:08 -0500 |
commit | 93a33ec208f52f6b999fe091823e3a3e63642ab3 (patch) | |
tree | 7dccdabdf876dcde469690e91b473ba96d4b8336 /actionview/lib/action_view | |
parent | 4cc1c14493e7a9bd188ee13c237366f6bc2e13f4 (diff) | |
parent | 504a9715ee60f0bc1bf67d6e81640e9bb6f29dfc (diff) | |
download | rails-93a33ec208f52f6b999fe091823e3a3e63642ab3.tar.gz rails-93a33ec208f52f6b999fe091823e3a3e63642ab3.tar.bz2 rails-93a33ec208f52f6b999fe091823e3a3e63642ab3.zip |
Merge pull request #28061 from andrewhood125/strip_tags_update
Remove `encode_special_chars` option from `strip_tags`
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r-- | actionview/lib/action_view/helpers/sanitize_helper.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/actionview/lib/action_view/helpers/sanitize_helper.rb b/actionview/lib/action_view/helpers/sanitize_helper.rb index 1e9b813d3d..0abd5bc5dc 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper.rb @@ -13,6 +13,7 @@ module ActionView # It also strips href/src attributes with unsafe protocols like # <tt>javascript:</tt>, while also protecting against attempts to use Unicode, # ASCII, and hex character references to work around these protocol filters. + # All special characters will be escaped. # # The default sanitizer is Rails::Html::WhiteListSanitizer. See {Rails HTML # Sanitizers}[https://github.com/rails/rails-html-sanitizer] for more information. @@ -20,8 +21,7 @@ module ActionView # Custom sanitization rules can also be provided. # # Please note that sanitizing user-provided text does not guarantee that the - # resulting markup is valid or even well-formed. For example, the output may still - # contain unescaped characters like <tt><</tt>, <tt>></tt>, or <tt>&</tt>. + # resulting markup is valid or even well-formed. # # ==== Options # @@ -86,7 +86,7 @@ module ActionView self.class.white_list_sanitizer.sanitize_css(style) end - # Strips all HTML tags from +html+, including comments. + # Strips all HTML tags from +html+, including comments and special characters. # # strip_tags("Strip <i>these</i> tags!") # # => Strip these tags! @@ -96,8 +96,11 @@ module ActionView # # strip_tags("<div id='top-bar'>Welcome to my website!</div>") # # => Welcome to my website! + # + # strip_tags("> A quote from Smith & Wesson") + # # => > A quote from Smith & Wesson def strip_tags(html) - self.class.full_sanitizer.sanitize(html, encode_special_chars: false) + self.class.full_sanitizer.sanitize(html) end # Strips all link tags from +html+ leaving just the link text. @@ -110,6 +113,9 @@ module ActionView # # strip_links('Blog: <a href="http://www.myblog.com/" class="nav" target=\"_blank\">Visit</a>.') # # => Blog: Visit. + # + # strip_links('<<a href="https://example.org">malformed & link</a>') + # # => <malformed & link def strip_links(html) self.class.link_sanitizer.sanitize(html) end |