diff options
author | Anton Davydov <antondavydov.o@gmail.com> | 2015-03-05 20:28:56 +0300 |
---|---|---|
committer | Anton Davydov <antondavydov.o@gmail.com> | 2015-03-05 20:51:48 +0300 |
commit | 4327feba28ba54bac92ec4bf65bf9930dc5876fe (patch) | |
tree | 579047d537d2dce89a474e910a5912d6527adbc1 /actionview | |
parent | 34d6a17d4d9690c25c686e1701103c0d70743819 (diff) | |
download | rails-4327feba28ba54bac92ec4bf65bf9930dc5876fe.tar.gz rails-4327feba28ba54bac92ec4bf65bf9930dc5876fe.tar.bz2 rails-4327feba28ba54bac92ec4bf65bf9930dc5876fe.zip |
[ci skip] Add information about sanitize option in TextHelper#highlight
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/text_helper.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index 2c40ed1832..c216d4401f 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -103,7 +103,9 @@ module ActionView # Highlights one or more +phrases+ everywhere in +text+ by inserting it into # a <tt>:highlighter</tt> string. The highlighter can be specialized by passing <tt>:highlighter</tt> # as a single-quoted string with <tt>\1</tt> where the phrase is to be inserted (defaults to - # '<mark>\1</mark>') or passing a block that receives each matched term. + # '<mark>\1</mark>') or passing a block that receives each matched term. By default +text+ + # is sanitized to prevent possible XSS attacks. If the input is trustworthy, passing false + # for <tt>:sanitize</tt> will turn sanitizing off. # # highlight('You searched for: rails', 'rails') # # => You searched for: <mark>rails</mark> @@ -122,6 +124,9 @@ module ActionView # # highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) } # # => You searched for: <a href="search?q=rails">rails</a> + # + # highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false) + # # => "<a>ruby</a> on <mark>rails</mark>" def highlight(text, phrases, options = {}) text = sanitize(text) if options.fetch(:sanitize, true) |