Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sanitize_options in simple_format helper #48355

Merged
merged 1 commit into from
Jun 1, 2023
Merged

Handle sanitize_options in simple_format helper #48355

merged 1 commit into from
Jun 1, 2023

Conversation

faraquet
Copy link

@faraquet faraquet commented May 31, 2023

Motivation / Background

We needed to open the links in a new window along with the simple_format from ActionView already used on the project. The problem is that Rails removes target="_blank" by default.

This pull request is based on @Rubyist007 solution.

[1] pry(main)> simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>")
=> "<p><a href=\"http://example.com\">Continue</a></p>"

I noticed that simple_format uses sanitize, but doesn't allow options for this, however, adding the extra sanitize options such as attributes: %w[target href] will resolve my issue.

text = sanitize(text) if options.fetch(:sanitize, true)

Details

This Pull Request introduces sanitize_options - Any extra options you want appending to the sanitize for the simple_format helper.

@rails-bot rails-bot bot added the actionview label May 31, 2023
@faraquet faraquet changed the title Pass sanitize_options to simple_format Handle sanitize_options in simple_format helper May 31, 2023
@guilleiguaran guilleiguaran merged commit 23a6576 into rails:main Jun 1, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants