Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a035ebbe
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a035ebbe
编写于
5月 02, 2017
作者:
B
Bob Van Landuyt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update path validation & specs
上级
c853dd61
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
58 addition
and
16 deletion
+58
-16
app/validators/dynamic_path_validator.rb
app/validators/dynamic_path_validator.rb
+18
-13
spec/validators/dynamic_path_validator_spec.rb
spec/validators/dynamic_path_validator_spec.rb
+40
-3
未找到文件。
app/validators/dynamic_path_validator.rb
浏览文件 @
a035ebbe
...
...
@@ -140,17 +140,17 @@ class DynamicPathValidator < ActiveModel::EachValidator
end
def
self
.
valid?
(
path
)
path
=~
Gitlab
::
Regex
.
full_namespace_regex
&&
!
reserved?
(
path
)
path
=~
Gitlab
::
Regex
.
full_namespace_regex
&&
!
full_path_
reserved?
(
path
)
end
def
self
.
reserved?
(
path
)
def
self
.
full_path_
reserved?
(
path
)
path
=
path
.
to_s
.
downcase
_project_part
s
,
namespace_parts
=
path
.
reverse
.
split
(
'/'
,
2
).
map
(
&
:reverse
)
_project_part
,
namespace_parts
=
path
.
reverse
.
split
(
'/'
,
2
).
map
(
&
:reverse
)
wildcard_reserved?
(
path
)
||
any
_reserved?
(
namespace_parts
)
wildcard_reserved?
(
path
)
||
child
_reserved?
(
namespace_parts
)
end
def
self
.
any
_reserved?
(
path
)
def
self
.
child
_reserved?
(
path
)
return
false
unless
path
path
!~
without_reserved_child_paths_regex
...
...
@@ -162,18 +162,23 @@ class DynamicPathValidator < ActiveModel::EachValidator
path
!~
without_reserved_wildcard_paths_regex
end
delegate
:reserved?
,
:
any
_reserved?
,
delegate
:
full_path_
reserved?
,
:
child
_reserved?
,
to: :class
def
valid_full_path
?
(
record
,
value
)
def
path_reserved_for_record
?
(
record
,
value
)
full_path
=
record
.
respond_to?
(
:full_path
)
?
record
.
full_path
:
value
case
record
when
Project
||
User
reserved?
(
full_path
)
# For group paths the entire path cannot contain a reserved child word
# The path doesn't contain the last `_project_part` so we need to validate
# if the entire path.
# Example:
# A *group* with full path `parent/activity` is reserved.
# A *project* with full path `parent/activity` is allowed.
if
record
.
is_a?
Group
child_reserved?
(
full_path
)
else
any
_reserved?
(
full_path
)
full_path
_reserved?
(
full_path
)
end
end
...
...
@@ -182,7 +187,7 @@ class DynamicPathValidator < ActiveModel::EachValidator
record
.
errors
.
add
(
attribute
,
Gitlab
::
Regex
.
namespace_regex_message
)
end
if
valid_full_path
?
(
record
,
value
)
if
path_reserved_for_record
?
(
record
,
value
)
record
.
errors
.
add
(
attribute
,
"
#{
value
}
is a reserved name"
)
end
end
...
...
spec/validators/dynamic_path_validator_spec.rb
浏览文件 @
a035ebbe
...
...
@@ -144,14 +144,19 @@ describe DynamicPathValidator do
end
end
describe
'.without_reserved_child_paths_regex'
do
it
'rejects paths containing a child reserved word'
do
subject
=
described_class
.
without_reserved_child_paths_regex
describe
'.regex_excluding_child_paths'
do
let
(
:subject
)
{
described_class
.
without_reserved_child_paths_regex
}
it
'rejects paths containing a child reserved word'
do
expect
(
subject
).
not_to
match
(
'hello/group_members'
)
expect
(
subject
).
not_to
match
(
'hello/activity/in-the-middle'
)
expect
(
subject
).
not_to
match
(
'foo/bar1/refs/master/logs_tree'
)
end
it
'allows a child path on the top level'
do
expect
(
subject
).
to
match
(
'activity/foo'
)
expect
(
subject
).
to
match
(
'avatar'
)
end
end
describe
".valid?"
do
...
...
@@ -195,4 +200,36 @@ describe DynamicPathValidator do
expect
(
described_class
.
valid?
(
test_path
)).
to
be_falsey
end
end
describe
'#path_reserved_for_record?'
do
it
'reserves a sub-group named activity'
do
group
=
build
(
:group
,
:nested
,
path:
'activity'
)
expect
(
validator
.
path_reserved_for_record?
(
group
,
'activity'
)).
to
be_truthy
end
it
"doesn't reserve a project called activity"
do
project
=
build
(
:project
,
path:
'activity'
)
expect
(
validator
.
path_reserved_for_record?
(
project
,
'activity'
)).
to
be_falsey
end
end
describe
'#validates_each'
do
it
'adds a message when the path is not in the correct format'
do
group
=
build
(
:group
)
validator
.
validate_each
(
group
,
:path
,
"Path with spaces, and comma's!"
)
expect
(
group
.
errors
[
:path
]).
to
include
(
Gitlab
::
Regex
.
namespace_regex_message
)
end
it
'adds a message when the path is not in the correct format'
do
group
=
build
(
:group
,
path:
'users'
)
validator
.
validate_each
(
group
,
:path
,
'users'
)
expect
(
group
.
errors
[
:path
]).
to
include
(
'users is a reserved name'
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录