diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/path_regex_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/path_regex_spec.rb')
-rw-r--r-- | spec/lib/gitlab/path_regex_spec.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/spec/lib/gitlab/path_regex_spec.rb b/spec/lib/gitlab/path_regex_spec.rb index 50b045c6aad..ac506c49100 100644 --- a/spec/lib/gitlab/path_regex_spec.rb +++ b/spec/lib/gitlab/path_regex_spec.rb @@ -3,6 +3,11 @@ require 'spec_helper' 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: # `/ci/lint(.:format)` -> `/ci/lint` def without_format(path) @@ -14,7 +19,7 @@ describe Gitlab::PathRegex do # `/*namespace_id/:project_id/builds/artifacts/*ref_name_and_path` # -> 'builds/artifacts' def path_before_wildcard(path) - path = path.gsub(STARTING_WITH_NAMESPACE, "") + path = path.gsub(starting_with_namespace, "") path_segments = path.split('/').reject(&:empty?) wildcard_index = path_segments.index { |segment| parameter?(segment) } @@ -121,13 +126,9 @@ describe Gitlab::PathRegex do # - Followed by one or more path-parts not starting with `:` or `*` # - Followed by a path-part that includes a wildcard parameter `*` # 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 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 @@ -145,16 +146,14 @@ describe Gitlab::PathRegex do end.uniq end - STARTING_WITH_GROUP = %r{^/groups/\*(group_)?id/}.freeze + let(:starting_with_group) { %r{^/groups/\*(group_)?id/} } let(:group_routes) do - routes_without_format.select do |path| - path =~ STARTING_WITH_GROUP - end + routes_without_format.grep(starting_with_group) end let(:paths_after_group_id) do group_routes.map do |route| - route.gsub(STARTING_WITH_GROUP, '').split('/').first + route.gsub(starting_with_group, '').split('/').first end.uniq end |