mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove regex alteration for custom routes
This was originally added in8d26f875f7
, and then updated to something closer to it's current form in https://github.com/rails/rails/pull/23140 The purpose was to alter the regexp for symbols surrounded by literals (for path parameters within path segments like "/foo-:bar" or "/:foo-bar") so that `default_regexp?` would return `false` for those symbols. `default_regexp?` was then used to partition the routes (see6ab985da28/actionpack/lib/action_dispatch/journey/routes.rb (L44)
). But after https://github.com/rails/rails/pull/41024, we're no longer partitioning routes using `default_regexp?` (in fact we're no longer using the method at all, so I've removed it). So I think it may now be possible to remove this. Prior to https://github.com/rails/rails/pull/41024, removing this code would have broken the tests added in https://github.com/rails/rails/pull/23140, but those tests now pass without it. I also tried this patch with the GitHub monolith and didn't get any test failures.
This commit is contained in:
parent
5f22ae4c94
commit
0011e098a1
3 changed files with 0 additions and 43 deletions
|
@ -86,10 +86,6 @@ module ActionDispatch
|
|||
@name = -left.tr("*:", "")
|
||||
end
|
||||
|
||||
def default_regexp?
|
||||
regexp == DEFAULT_EXP
|
||||
end
|
||||
|
||||
def type; :SYMBOL; end
|
||||
def symbol?; true; end
|
||||
end
|
||||
|
|
|
@ -136,8 +136,6 @@ module ActionDispatch
|
|||
# Add a constraint for wildcard route to make it non-greedy and match the
|
||||
# optional format part of the route by default.
|
||||
wildcard_options[node.name.to_sym] ||= /.+?/
|
||||
elsif node.cat?
|
||||
alter_regex_for_custom_routes(node)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -211,24 +209,6 @@ module ActionDispatch
|
|||
private :request_method
|
||||
|
||||
private
|
||||
# Find all the symbol nodes that are adjacent to literal nodes and alter
|
||||
# the regexp so that Journey will partition them into custom routes.
|
||||
def alter_regex_for_custom_routes(node)
|
||||
if node.left.literal? && node.right.symbol?
|
||||
symbol = node.right
|
||||
elsif node.left.literal? && node.right.cat? && node.right.left.symbol?
|
||||
symbol = node.right.left
|
||||
elsif node.left.symbol? && node.right.literal?
|
||||
symbol = node.left
|
||||
elsif node.left.symbol? && node.right.cat? && node.right.left.literal?
|
||||
symbol = node.left
|
||||
end
|
||||
|
||||
if symbol
|
||||
symbol.regexp = /(?:#{Regexp.union(symbol.regexp, '-')})+/
|
||||
end
|
||||
end
|
||||
|
||||
def intern(object)
|
||||
object.is_a?(String) ? -object : object
|
||||
end
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_unit"
|
||||
|
||||
module ActionDispatch
|
||||
module Journey
|
||||
module Nodes
|
||||
class TestSymbol < ActiveSupport::TestCase
|
||||
def test_default_regexp?
|
||||
sym = Symbol.new "foo"
|
||||
assert_predicate sym, :default_regexp?
|
||||
|
||||
sym.regexp = nil
|
||||
assert_not_predicate sym, :default_regexp?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue