summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-04-24 12:22:51 +0200
committerBob Van Landuyt <bob@gitlab.com>2017-05-01 11:14:24 +0200
commitea8e86dac856fdf6545e020df346533231379b93 (patch)
tree2309bba6e9dff9f91cc0fbb4a90fd374550c165e
parent39efd0c03018089366d5301583a605626e97e9d7 (diff)
downloadgitlab-ce-ea8e86dac856fdf6545e020df346533231379b93.tar.gz
Use `%r{}` regexes to avoid having to escape `/`
-rw-r--r--app/validators/dynamic_path_validator.rb2
-rw-r--r--spec/validators/dynamic_path_validator_spec.rb10
2 files changed, 6 insertions, 6 deletions
diff --git a/app/validators/dynamic_path_validator.rb b/app/validators/dynamic_path_validator.rb
index 6f04263d4d5..ae2bd5984c5 100644
--- a/app/validators/dynamic_path_validator.rb
+++ b/app/validators/dynamic_path_validator.rb
@@ -104,7 +104,7 @@ class DynamicPathValidator < ActiveModel::EachValidator
end
def self.contains_path_part?(path, part)
- path =~ /(.*\/|\A)#{Regexp.quote(part)}(\/.*|\z)/
+ path =~ %r{(/|\A)#{Regexp.quote(part)}(/|\z)}
end
def self.follow_format?(value)
diff --git a/spec/validators/dynamic_path_validator_spec.rb b/spec/validators/dynamic_path_validator_spec.rb
index 71098b17dfd..960a6204c90 100644
--- a/spec/validators/dynamic_path_validator_spec.rb
+++ b/spec/validators/dynamic_path_validator_spec.rb
@@ -63,13 +63,13 @@ describe DynamicPathValidator 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 = /^\/\*namespace_id\/:(project_)?id/
- NON_PARAM_PARTS = /[^:*][a-z\-_\/]*/
- ANY_OTHER_PATH_PART = /[a-z\-_\/:]*/
- WILDCARD_SEGMENT = /\*/
+ STARTING_WITH_NAMESPACE = %r{^/\*namespace_id/:(project_)?id}
+ NON_PARAM_PARTS = %r{[^:*][a-z\-_/]*}
+ ANY_OTHER_PATH_PART = %r{[a-z\-_/:]*}
+ WILDCARD_SEGMENT = %r{\*}
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