diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-03-05 19:22:32 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-03-05 19:22:32 +0100 |
commit | 861af7e94bbd5c5e6f2e8bab491f63ac18a2ed44 (patch) | |
tree | 4ce5de1659b0f2f5f90d02cbbfac89af20056930 | |
parent | a26afeab9599bbb077c08ef13ea2d370d7340dc9 (diff) | |
parent | 4327feba28ba54bac92ec4bf65bf9930dc5876fe (diff) | |
download | rails-861af7e94bbd5c5e6f2e8bab491f63ac18a2ed44.tar.gz rails-861af7e94bbd5c5e6f2e8bab491f63ac18a2ed44.tar.bz2 rails-861af7e94bbd5c5e6f2e8bab491f63ac18a2ed44.zip |
Merge pull request #19220 from davydovanton/doc-add-info-about-sanitize-to-highlight
[ci skip] Add information about sanitize option in TextHelper#highlight
-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) |