Rails:ParameterFilter::compiled_filter 尝试复制符号
我正在使用 Rails 异常通知程序 gem 运行 Rails3。当发生异常并且应该发送电子邮件时,我从 ParameterFilter 类收到异常。我在 Rails 源代码中发现了问题,但不确定继续的最佳方法。
问题出现在 ActionDispatch::Http::ParameterFilter 中。在compile_filter方法中,当key
是符号时,第38行会出现错误:key = key.dup
,因为符号不可重复。这是来源:
def compiled_filter
...
elsif blocks.present?
key = key.dup
value = value.dup if value.duplicable?
blocks.each { |b| b.call(key, value) }
end
我看到他们只在可复制
时对value
调用dup
。如果我修补源代码,仅在 key
是 可复制
时对 key
调用 dup
,那么我的问题就消失了。我假设作者将该条件放在 value
而不是 key
上是有原因的,所以我很好奇是否有人对这段代码有更好的理解。
仅当您将块添加到 application.rb 中的过滤器参数时,才会发生此错误。因此,也许我原来的问题有一个解决方法,不需要在这里使用块。如果您有兴趣,请参阅我同事的问题 Rails:过滤敏感数据日志中的 JSON 参数
出现此问题的关键是 :action
。这来自 Rails,我不知道是否有任何方法可以强制它成为字符串。
我提交了一个 Rails 错误 https:/ /rails.lighthouseapp.com/projects/8994/tickets/6557-symbol-duplication-error-in-parameterfilter-compiled_filter 并且我已经准备好一个补丁,添加 if key.duplicable?
对于 key.dup
行,我正在寻找有关这是否是正确解决方案的输入。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来像是 Rails 中的一个错误。要么键应该是字符串而不是符号,要么
dup
应该受到duplicable?
保护。您应该在 https://rails.lighthouseapp.com/ 提交错误,如果可能的话,包括一个最小的测试用例。
This looks like a bug in Rails. Either the key should be a string rather than a symbol, or the
dup
should be protected byduplicable?
.You should file a bug at https://rails.lighthouseapp.com/, including a minimal test case if possible.