提交 c86750c3 编写于 作者: R Ryuta Kamizono

Merge pull request #37435 from abhaynikam/37428-fix-filter-attributes-for-json-data-type

Closes #37435.
# frozen_string_literal: true
require "support/schema_dumping_helper"
require "pp"
module JSONSharedTestCases
include SchemaDumpingHelper
......@@ -249,6 +250,25 @@ def test_json_with_serialized_attributes
assert_equal({ "three" => "four" }, record.reload.settings.to_hash)
end
class JsonDataTypeWithFilter < ActiveRecord::Base
self.table_name = "json_data_type"
attribute :payload, :json
def self.filter_attributes
# Rails.application.config.filter_parameters += [:password]
super + [:password]
end
end
def test_pretty_print
x = JsonDataTypeWithFilter.create!(payload: {})
x.payload[11] = "foo"
io = StringIO.new
PP.pp(x, io)
assert io.string
end
private
def klass
JsonDataType
......
......@@ -107,7 +107,7 @@ def call(params, parents = [], original_params = params)
def value_for_key(key, value, parents = [], original_params = nil)
parents.push(key) if deep_regexps
if regexps.any? { |r| r.match?(key) }
if regexps.any? { |r| r.match?(key.to_s) }
value = @mask
elsif deep_regexps && (joined = parents.join(".")) && deep_regexps.any? { |r| r.match?(joined) }
value = @mask
......
......@@ -109,4 +109,16 @@ class ParameterFilterTest < ActiveSupport::TestCase
assert_equal mask, parameter_filter.filter_param("barbar", "secret vlaue")
assert_equal "non secret value", parameter_filter.filter_param("baz", "non secret value")
end
test "process parameter filter with hash having integer keys" do
test_hashes = [
[{ 13 => "bar" }, { 13 => "[FILTERED]" }, %w'13'],
[{ 20 => "bar" }, { 20 => "bar" }, %w'13'],
]
test_hashes.each do |before_filter, after_filter, filter_words|
parameter_filter = ActiveSupport::ParameterFilter.new(filter_words)
assert_equal after_filter, parameter_filter.filter(before_filter)
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册