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
45e8fb07
Commit
45e8fb07
authored
May 21, 2020
by
Rajendra Kadam
Committed by
Peter Leitzen
May 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix leaky constant issue in path regex spec
parent
3be73a7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
.rubocop.yml
.rubocop.yml
+0
-1
changelogs/unreleased/leaky-constant-fix-30.yml
changelogs/unreleased/leaky-constant-fix-30.yml
+5
-0
spec/lib/gitlab/path_regex_spec.rb
spec/lib/gitlab/path_regex_spec.rb
+10
-11
No files found.
.rubocop.yml
View file @
45e8fb07
...
@@ -361,7 +361,6 @@ RSpec/LeakyConstantDeclaration:
...
@@ -361,7 +361,6 @@ RSpec/LeakyConstantDeclaration:
-
'
spec/lib/gitlab/git/diff_collection_spec.rb'
-
'
spec/lib/gitlab/git/diff_collection_spec.rb'
-
'
spec/lib/gitlab/import_export/import_test_coverage_spec.rb'
-
'
spec/lib/gitlab/import_export/import_test_coverage_spec.rb'
-
'
spec/lib/gitlab/import_export/project/relation_factory_spec.rb'
-
'
spec/lib/gitlab/import_export/project/relation_factory_spec.rb'
-
'
spec/lib/gitlab/path_regex_spec.rb'
-
'
spec/lib/gitlab/quick_actions/dsl_spec.rb'
-
'
spec/lib/gitlab/quick_actions/dsl_spec.rb'
-
'
spec/lib/marginalia_spec.rb'
-
'
spec/lib/marginalia_spec.rb'
-
'
spec/mailers/notify_spec.rb'
-
'
spec/mailers/notify_spec.rb'
...
...
changelogs/unreleased/leaky-constant-fix-30.yml
0 → 100644
View file @
45e8fb07
---
title
:
Fix leaky constant issue in path regex spec
merge_request
:
32115
author
:
Rajendra Kadam
type
:
fixed
spec/lib/gitlab/path_regex_spec.rb
View file @
45e8fb07
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
PathRegex
do
describe
Gitlab
::
PathRegex
do
let
(
:starting_with_namespace
)
{
%r{^/
\*
namespace_id/:(project_)?id}
}
let
(
:non_param_parts
)
{
%r{[^:*][a-z
\-
_/]*}
}
let
(
:any_other_path_part
)
{
%r{[a-z
\-
_/:]*}
}
let
(
:wildcard_segment
)
{
/\*/
}
# Pass in a full path to remove the format segment:
# Pass in a full path to remove the format segment:
# `/ci/lint(.:format)` -> `/ci/lint`
# `/ci/lint(.:format)` -> `/ci/lint`
def
without_format
(
path
)
def
without_format
(
path
)
...
@@ -14,7 +19,7 @@ describe Gitlab::PathRegex do
...
@@ -14,7 +19,7 @@ describe Gitlab::PathRegex do
# `/*namespace_id/:project_id/builds/artifacts/*ref_name_and_path`
# `/*namespace_id/:project_id/builds/artifacts/*ref_name_and_path`
# -> 'builds/artifacts'
# -> 'builds/artifacts'
def
path_before_wildcard
(
path
)
def
path_before_wildcard
(
path
)
path
=
path
.
gsub
(
STARTING_WITH_NAMESPACE
,
""
)
path
=
path
.
gsub
(
starting_with_namespace
,
""
)
path_segments
=
path
.
split
(
'/'
).
reject
(
&
:empty?
)
path_segments
=
path
.
split
(
'/'
).
reject
(
&
:empty?
)
wildcard_index
=
path_segments
.
index
{
|
segment
|
parameter?
(
segment
)
}
wildcard_index
=
path_segments
.
index
{
|
segment
|
parameter?
(
segment
)
}
...
@@ -121,13 +126,9 @@ describe Gitlab::PathRegex do
...
@@ -121,13 +126,9 @@ describe Gitlab::PathRegex do
# - Followed by one or more path-parts not starting with `:` or `*`
# - Followed by one or more path-parts not starting with `:` or `*`
# - Followed by a path-part that includes a wildcard parameter `*`
# - Followed by a path-part that includes a wildcard parameter `*`
# At the time of writing these routes match: http://rubular.com/r/Rv2pDE5Dvw
# At the time of writing these routes match: http://rubular.com/r/Rv2pDE5Dvw
STARTING_WITH_NAMESPACE
=
%r{^/
\*
namespace_id/:(project_)?id}
.
freeze
NON_PARAM_PARTS
=
%r{[^:*][a-z
\-
_/]*}
.
freeze
ANY_OTHER_PATH_PART
=
%r{[a-z
\-
_/:]*}
.
freeze
WILDCARD_SEGMENT
=
/\*/
.
freeze
let
(
:namespaced_wildcard_routes
)
do
let
(
:namespaced_wildcard_routes
)
do
routes_without_format
.
select
do
|
p
|
routes_without_format
.
select
do
|
p
|
p
=~
%r{
#{
STARTING_WITH_NAMESPACE
}
/
#{
NON_PARAM_PARTS
}
/
#{
ANY_OTHER_PATH_PART
}#{
WILDCARD_SEGMENT
}
}
p
=~
%r{
#{
starting_with_namespace
}
/
#{
non_param_parts
}
/
#{
any_other_path_part
}#{
wildcard_segment
}
}
end
end
end
end
...
@@ -145,16 +146,14 @@ describe Gitlab::PathRegex do
...
@@ -145,16 +146,14 @@ describe Gitlab::PathRegex do
end
.
uniq
end
.
uniq
end
end
STARTING_WITH_GROUP
=
%r{^/groups/
\*
(group_)?id/}
.
freeze
let
(
:starting_with_group
)
{
%r{^/groups/
\*
(group_)?id/}
}
let
(
:group_routes
)
do
let
(
:group_routes
)
do
routes_without_format
.
select
do
|
path
|
routes_without_format
.
grep
(
starting_with_group
)
path
=~
STARTING_WITH_GROUP
end
end
end
let
(
:paths_after_group_id
)
do
let
(
:paths_after_group_id
)
do
group_routes
.
map
do
|
route
|
group_routes
.
map
do
|
route
|
route
.
gsub
(
STARTING_WITH_GROUP
,
''
).
split
(
'/'
).
first
route
.
gsub
(
starting_with_group
,
''
).
split
(
'/'
).
first
end
.
uniq
end
.
uniq
end
end
...
...
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