Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c86750c3
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c86750c3
编写于
2月 28, 2020
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #37435 from abhaynikam/37428-fix-filter-attributes-for-json-data-type
Closes #37435.
上级
5f596e29
339d1cdc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
1 deletion
+33
-1
activerecord/test/cases/json_shared_test_cases.rb
activerecord/test/cases/json_shared_test_cases.rb
+20
-0
activesupport/lib/active_support/parameter_filter.rb
activesupport/lib/active_support/parameter_filter.rb
+1
-1
activesupport/test/parameter_filter_test.rb
activesupport/test/parameter_filter_test.rb
+12
-0
未找到文件。
activerecord/test/cases/json_shared_test_cases.rb
浏览文件 @
c86750c3
# 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
...
...
activesupport/lib/active_support/parameter_filter.rb
浏览文件 @
c86750c3
...
...
@@ -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
...
...
activesupport/test/parameter_filter_test.rb
浏览文件 @
c86750c3
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录