Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
50b5fcae
Commit
50b5fcae
authored
Jun 14, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure scope has the right format
parent
cc0a899b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
2 deletions
+49
-2
app/models/ci/variable.rb
app/models/ci/variable.rb
+6
-1
app/models/ee/ci/variable.rb
app/models/ee/ci/variable.rb
+24
-0
lib/ee/gitlab/regex.rb
lib/ee/gitlab/regex.rb
+13
-0
lib/gitlab/regex.rb
lib/gitlab/regex.rb
+1
-0
spec/models/ci/variable_spec.rb
spec/models/ci/variable_spec.rb
+5
-1
No files found.
app/models/ci/variable.rb
View file @
50b5fcae
module
Ci
class
Variable
<
ActiveRecord
::
Base
extend
Ci
::
Model
prepend
EE
::
Ci
::
Variable
def
self
.
key_uniqueness_scope
:project_id
end
belongs_to
:project
validates
:key
,
presence:
true
,
uniqueness:
{
scope:
%i[project_id scope]
},
uniqueness:
{
scope:
key_uniqueness_scope
},
length:
{
maximum:
255
},
format:
{
with:
/\A[a-zA-Z0-9_]+\z/
,
message:
"can contain only letters, digits and '_'."
}
...
...
app/models/ee/ci/variable.rb
0 → 100644
View file @
50b5fcae
module
EE
module
Ci
module
Variable
extend
ActiveSupport
::
Concern
module
VariableClassMethods
def
key_uniqueness_scope
%i[project_id scope]
end
end
prepended
do
singleton_class
.
prepend
(
VariableClassMethods
)
validates
(
:scope
,
presence:
true
,
format:
{
with:
::
Gitlab
::
Regex
.
variable_scope_regex
,
message:
::
Gitlab
::
Regex
.
variable_scope_regex_message
}
)
end
end
end
end
lib/ee/gitlab/regex.rb
0 → 100644
View file @
50b5fcae
module
EE
module
Gitlab
module
Regex
def
variable_scope_regex
@variable_scope_regex
||=
/\A[a-zA-Z0-9_\\\/\${}. -*]+\z/
.
freeze
end
def
variable_scope_regex_message
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
end
end
end
end
lib/gitlab/regex.rb
View file @
50b5fcae
module
Gitlab
module
Regex
extend
self
extend
EE
::
Gitlab
::
Regex
def
namespace_name_regex
@namespace_name_regex
||=
/\A[\p{Alnum}\p{Pd}_\. ]*\z/
.
freeze
...
...
spec/models/ci/variable_spec.rb
View file @
50b5fcae
...
...
@@ -11,7 +11,11 @@ describe Ci::Variable, models: true do
it
{
is_expected
.
not_to
allow_value
(
'foo bar'
).
for
(
:key
)
}
it
{
is_expected
.
not_to
allow_value
(
'foo/bar'
).
for
(
:key
)
}
if
described_class
.
column_names
.
include?
(
'scope'
)
# EE
it
{
is_expected
.
to
allow_value
(
'review/*'
).
for
(
:scope
)
}
it
{
is_expected
.
not_to
allow_value
(
''
).
for
(
:scope
)
}
if
defined?
(
EE
::
Ci
::
Variable
)
it
{
is_expected
.
to
validate_uniqueness_of
(
:key
).
scoped_to
(
:project_id
,
:scope
)
}
else
it
{
is_expected
.
to
validate_uniqueness_of
(
:key
).
scoped_to
(
:project_id
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment