Rails:ParameterFilter :: compiled_filter尝试复制符号 [英] Rails: ParameterFilter::compiled_filter tries to dup symbol

查看:86
本文介绍了Rails:ParameterFilter :: compiled_filter尝试复制符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行带有rails exception-notifier gem的rails3。当发生异常并应发送电子邮件时,我从ParameterFilter类中获取了异常。我已经在rails源中找到了问题,并且不确定最好的处理方法。



该问题发生在ActionDispatch :: Http :: ParameterFilter中。在compiled_filter方法中,第38行发生错误: key 是符号时, key = key.dup 符号不可重复。来源是:

  def编译过滤器
...
elsif blocks.present吗?
key = key.dup
value = value.dup如果value.duplicable?
个块。每个{| b | b.call(key,value)}
结尾

我看到他们只调用< dupable 中的的code> dup 。如果我将源修补为仅在 key key 上的 dup c>是可复制的,那么我的问题就消失了。我假设作者将条件放在 value 而不是 key 上是有原因的,所以我



仅当您向application.rb中的过滤器参数添加块时,才会发生此错误。因此,也许有一个针对我原始问题的解决方法,不需要在此处使用块。如果您有兴趣,请参阅我的同事的问题 Rails:过滤敏感数据日志中的JSON参数中



出现问题的键是:action 。这来自rails,我不知道是否有任何方法可以将其强制为字符串。



我提交了Rails错误 https://rails.lighthouseapp.com/projects/8994/ tickets / 6557-symbol-duplication-error-in-parameterfilter-compiled_filter ,我准备好了一个补丁,如果 key.duplicable?添加到 key.dup 行,我正在寻找有关这是否是正确解决方案的输入。

解决方案

这看起来像Rails中的错误。密钥应该是字符串而不是符号,或者 dup 应该受 duplicable?保护。 p>

您应该在 https://rails.lighthouseapp.com上提交错误。 / ,包括一个最小的测试用例。


I'm running rails3 with rails exception-notifier gem. When an exception occurs, and an email should be sent, I'm getting an exception from the ParameterFilter class. I've found the problem in the rails source, and am not sure the best way to proceed.

The problem occurs in ActionDispatch::Http::ParameterFilter. In the compiled_filter method, an error occurs on line 38: key = key.dup when key is a symbol, because symbols are not duplicable. Here is the source:

def compiled_filter
    ...
    elsif blocks.present?
        key = key.dup
        value = value.dup if value.duplicable?
        blocks.each { |b| b.call(key, value) }
    end

I see that they only call dup on value when it is duplicable. If I patch the source to only call dup on key when key is duplicable, then my problem goes away. I'm assuming there is a reason why the author put that condition on value and not key, so I'm curious if someone out there has a better understanding of this code.

This error only occurs when you add a block to your filter params in application.rb. So, maybe there is a workaround for my original issue that does not require using a block here. If you're interested see my coworker's question Rails: Filter sensitive data in JSON parameter from logs

The key for which this is a problem is :action. This comes from rails and I don't know if there is any way to force it to be a string instead.

I filed a rails bug https://rails.lighthouseapp.com/projects/8994/tickets/6557-symbol-duplication-error-in-parameterfilter-compiled_filter and I have a patch ready that adds if key.duplicable? to the key.dup line, I'm looking for input on whether or not that is the right solution.

解决方案

This looks like a bug in Rails. Either the key should be a string rather than a symbol, or the dup should be protected by duplicable?.

You should file a bug at https://rails.lighthouseapp.com/, including a minimal test case if possible.

这篇关于Rails:ParameterFilter :: compiled_filter尝试复制符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆