简体   繁体   中英

Rails sanitizer: Allow certain styles in style attribute

I'm using the rails-html-sanitizer and I am currently whitelisting the style attribute. However, I only want to allow certain styles to be whitelisted.

Is it possible to specify which styles to allow? For example, allow the following:

style="text-align: center;"

In the documentation I see the following, but I think it does the opposite of what I'm trying to do: white_list_sanitizer.sanitize_css('background-color: #000;')

In the case that I can't whitelist certain styles, my next option was to just attach the styles to certain classes.

If you read the code in the ActionView sanitize helper you can actually see that passing additional options was never intended.

As such, it is not possible to whitelist only certain style attributes with the rails helper.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM