Commit ea8e86da authored by Bob Van Landuyt's avatar Bob Van Landuyt

Use `%r{}` regexes to avoid having to escape `/`

parent 39efd0c0
...@@ -104,7 +104,7 @@ class DynamicPathValidator < ActiveModel::EachValidator ...@@ -104,7 +104,7 @@ class DynamicPathValidator < ActiveModel::EachValidator
end end
def self.contains_path_part?(path, part) def self.contains_path_part?(path, part)
path =~ /(.*\/|\A)#{Regexp.quote(part)}(\/.*|\z)/ path =~ %r{(/|\A)#{Regexp.quote(part)}(/|\z)}
end end
def self.follow_format?(value) def self.follow_format?(value)
......
...@@ -63,13 +63,13 @@ describe DynamicPathValidator do ...@@ -63,13 +63,13 @@ describe DynamicPathValidator 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 = /^\/\*namespace_id\/:(project_)?id/ STARTING_WITH_NAMESPACE = %r{^/\*namespace_id/:(project_)?id}
NON_PARAM_PARTS = /[^:*][a-z\-_\/]*/ NON_PARAM_PARTS = %r{[^:*][a-z\-_/]*}
ANY_OTHER_PATH_PART = /[a-z\-_\/:]*/ ANY_OTHER_PATH_PART = %r{[a-z\-_/:]*}
WILDCARD_SEGMENT = /\*/ WILDCARD_SEGMENT = %r{\*}
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment