Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d12b30f9
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,体验更适合开发者的 AI 搜索 >>
提交
d12b30f9
编写于
7月 16, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15944 from seuros/uuid
Treat invalid uuid as nil Conflicts: activerecord/CHANGELOG.md
上级
df8b0211
f378f236
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
1 deletion
+51
-1
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb
.../active_record/connection_adapters/postgresql/oid/uuid.rb
+10
-1
activerecord/test/cases/adapters/postgresql/uuid_test.rb
activerecord/test/cases/adapters/postgresql/uuid_test.rb
+37
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
d12b30f9
*
PostgreSQL invalid
`uuid`
are convert to nil.
*Abdelkader Boudih*
*
Restore 4.0 behavior for using serialize attributes with
`JSON`
as coder.
With 4.1.x, `serialize` started returning a string when `JSON` was passed as
...
...
activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb
浏览文件 @
d12b30f9
...
...
@@ -3,12 +3,21 @@ module ConnectionAdapters
module
PostgreSQL
module
OID
# :nodoc:
class
Uuid
<
Type
::
Value
# :nodoc:
RFC_4122
=
%r{
\A\{
?[a-fA-F0-9]{4}-?
[a-fA-F0-9]{4}-?
[a-fA-F0-9]{4}-?
[1-5][a-fA-F0-9]{3}-?
[8-Bab][a-fA-F0-9]{3}-?
[a-fA-F0-9]{4}-?
[a-fA-F0-9]{4}-?
[a-fA-F0-9]{4}-?
\}
?
\z
}x
def
type
:uuid
end
def
type_cast
(
value
)
value
.
presence
value
.
to_s
[
RFC_4122
,
0
]
end
end
end
...
...
activerecord/test/cases/adapters/postgresql/uuid_test.rb
浏览文件 @
d12b30f9
...
...
@@ -60,6 +60,43 @@ def test_treat_blank_uuid_as_nil
assert_equal
(
nil
,
UUIDType
.
last
.
guid
)
end
def
test_treat_invalid_uuid_as_nil
uuid
=
UUIDType
.
create!
guid:
'foobar'
assert_equal
(
nil
,
uuid
.
guid
)
end
def
test_invalid_uuid_dont_modify_before_type_cast
uuid
=
UUIDType
.
new
guid:
'foobar'
assert_equal
'foobar'
,
uuid
.
guid_before_type_cast
end
def
test_rfc_4122_regex
# Valid uuids
[
'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11'
,
'{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}'
,
'a0eebc999c0b4ef8bb6d6bb9bd380a11'
,
'a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11'
,
'{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}'
].
each
do
|
valid_uuid
|
uuid
=
UUIDType
.
new
guid:
valid_uuid
assert_not_nil
uuid
.
guid
end
# Invalid uuids
[[
'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11'
],
Hash
.
new
,
0
,
0.0
,
true
,
'Z0000C99-9C0B-4EF8-BB6D-6BB9BD380A11'
,
'{a0eebc99-9c0b-4ef8-fb6d-6bb9bd380a11}'
,
'a0eebc999r0b4ef8ab6d6bb9bd380a11'
,
'a0ee-bc99------4ef8-bb6d-6bb9-bd38-0a11'
,
'{a0eebc99-bb6d6bb9-bd380a11}'
].
each
do
|
invalid_uuid
|
uuid
=
UUIDType
.
new
guid:
invalid_uuid
assert_nil
uuid
.
guid
end
end
def
test_uuid_formats
[
"A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11"
,
"{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录