-
Notifications
You must be signed in to change notification settings - Fork 21.9k
ActionText::ContentHelper.allowed_tags (and attributes) are no longer easily added to #54478
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
Comments
which were being set to the HTML4 defaults before the sanitizer configuration could be applied. Also, backfill some light tests for sanitization. Related to #48644
One proposed solution was this:
Having to initialise the module into a new class just to get at the defaults feels backward. |
This has been challenging to get right because Action Text doesn't have a default set of allowed tags and attributes, it delegates that to the sanitizer, which is also configurable. How would you feel if the recommended idiom for adding allowed tags and attrs was something like: ActiveSupport.on_load :action_text_content do
ActionText::ContentHelper.extra_allowed_tags = ["embed"]
ActionText::ContentHelper.extra_allowed_attributes = ["foobar"]
end The idea is that the allowlist would be the union of the sanitizer's allowlist and the "extra_allowed" values. |
That would work in my case as I just want to add extra tags but I wonder about the case when someone wants to remove a default tag. I suppose it would be weird for them to be removing the trix defaults and they can manipulate the sanitiser defaults elsewhere. Would it be better to make this an official configuration option? Something like:
|
|
@Alexander-Senko What I am trying to say is that Action View has no opinion on allowed attributes and tags; it relies on the underlying sanitizer's lists, and that's why the default value is now The problem I think we need to solve first is "how to safely modify the allowlist" and not "I need my code to know what the default is", because I imagine the most common reason people need to know that is ... to safely modify it. No? |
To be clear, I want to solve both problems. I'm trying to share my mental models to move the conversation forward. |
At the same time |
I agree it is inconsistent and I've said several times already in this thread that I want to fix it. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
Not Stale |
Since Rails 7.1 and this change in particular:
e8137c5#diff-3ae50dc6dc778a98f32121997298af3643f7ca400cd35638a1236948a10fedd3R58
We can no longer easily add additional
allowed_tags
to ActionText::ContentHelper because it's computed at runtime and there's no configuration option.Expected behavior
One could previously do this in an initialiser to add additional tags:
Actual behavior
Now that raises an error saying allowed_tags is
nil
because it has no default value.System configuration
Rails version: 7.1+
Ruby version: Any
Probably the best way forward is to add this as a configuration option unless a better option exists?
https://stackoverflow.com/questions/77366033/allow-actiontext-tags-in-rails-7-1-with-new-sanitizers
@flavorjones, issue opened at your request :)
The text was updated successfully, but these errors were encountered: