代码之家  ›  专栏  ›  技术社区  ›  tquill

Rails sanitize不允许rgb颜色

  •  0
  • tquill  · 技术社区  · 7 年前

    我有一个wysiwyg,允许用户格式化文本区域。我正在使用 sanitize 我正在传入允许标记和允许属性的数组:

    <%= sanitize @record.notes, tags: %w(strong em u div span br h1 h2 h3 h4 ul ol li table thead tbody th tr td img hr a), attributes: %w(style colspan rowspan text-align class href target src href) %>

    除了使用rgb指定颜色的样式属性外,其他所有属性都正常工作。

    例如,此输入正确显示颜色:

    <span style="color: red;">PRODUCTS</span>

    但此输入不起作用,并且样式属性为空:

    <span style="color: rgb(226, 80, 65);">PRODUCTS</span>

    有没有办法让rgb颜色正常工作?

    编辑:作为参考,我在Rails 4.2.10上。

    2 回复  |  直到 7 年前
        1
  •  0
  •   olucube.com    7 年前

    看起来你需要做的是找到正确的rgb组合,因为当我尝试这个时

    <span style="color: rgb(255, 0, 0);">PRODUCTS 1</span>
    

    这里是红色

    <span style="color: red;">PRODUCTS</span>
    

    也许您需要使用颜色选择器来了解在需要匹配颜色时要使用什么rgb组合

        2
  •  0
  •   tquill    7 年前

    显然地 Loofah 处理引擎盖下的消毒功能,默认情况下会删除一些功能。RGB颜色似乎被视为一种功能。

    当前有一个 pull request 允许将应解决此问题的特定函数列入白名单。