aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/journey/nodes/node.rb2
-rw-r--r--actionpack/lib/action_dispatch/journey/path/pattern.rb4
-rw-r--r--actionpack/lib/action_dispatch/journey/route.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb4
-rw-r--r--actionpack/test/journey/path/pattern_test.rb26
-rw-r--r--actionpack/test/journey/route_test.rb2
6 files changed, 23 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/journey/nodes/node.rb b/actionpack/lib/action_dispatch/journey/nodes/node.rb
index cf6542b370..a2de6ce1c8 100644
--- a/actionpack/lib/action_dispatch/journey/nodes/node.rb
+++ b/actionpack/lib/action_dispatch/journey/nodes/node.rb
@@ -39,10 +39,12 @@ module ActionDispatch
def symbol?; false; end
def literal?; false; end
+ def terminal?; false; end
end
class Terminal < Node # :nodoc:
alias :symbol :left
+ def terminal?; true; end
end
class Literal < Terminal # :nodoc:
diff --git a/actionpack/lib/action_dispatch/journey/path/pattern.rb b/actionpack/lib/action_dispatch/journey/path/pattern.rb
index 24b90e214d..cb1a65e1f4 100644
--- a/actionpack/lib/action_dispatch/journey/path/pattern.rb
+++ b/actionpack/lib/action_dispatch/journey/path/pattern.rb
@@ -5,7 +5,7 @@ module ActionDispatch
attr_reader :spec, :requirements, :anchored
def self.from_string string
- build(string, {}, ["/.?"], true)
+ build(string, {}, "/.?", true)
end
def self.build(path, requirements, separators, anchored)
@@ -17,7 +17,7 @@ module ActionDispatch
def initialize(ast, requirements, separators, anchored)
@spec = ast
@requirements = requirements
- @separators = separators.join
+ @separators = separators
@anchored = anchored
@names = nil
diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb
index 1ead6c8a82..7fcb4080e8 100644
--- a/actionpack/lib/action_dispatch/journey/route.rb
+++ b/actionpack/lib/action_dispatch/journey/route.rb
@@ -30,7 +30,7 @@ module ActionDispatch
def ast
@decorated_ast ||= begin
decorated_ast = path.ast
- decorated_ast.grep(Nodes::Terminal).each { |n| n.memo = self }
+ decorated_ast.find_all(&:terminal?).each { |n| n.memo = self }
decorated_ast
end
end
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index a9dae77e51..2c9cab605f 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -185,8 +185,10 @@ module ActionDispatch
end
private :build_conditions
+ JOINED_SEPARATORS = SEPARATORS.join # :nodoc:
+
def build_path(ast, requirements, anchor)
- pattern = Journey::Path::Pattern.new(ast, requirements, SEPARATORS, anchor)
+ pattern = Journey::Path::Pattern.new(ast, requirements, JOINED_SEPARATORS, anchor)
builder = Journey::GTG::Builder.new ast
diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb
index 7b97379bd5..72858f5eda 100644
--- a/actionpack/test/journey/path/pattern_test.rb
+++ b/actionpack/test/journey/path/pattern_test.rb
@@ -4,6 +4,8 @@ module ActionDispatch
module Journey
module Path
class TestPattern < ActiveSupport::TestCase
+ SEPARATORS = ["/", ".", "?"].join
+
x = /.+/
{
'/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?\Z},
@@ -22,7 +24,7 @@ module ActionDispatch
path = Pattern.build(
path,
{ :controller => /.+/ },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_equal(expected, path.to_regexp)
@@ -46,7 +48,7 @@ module ActionDispatch
path = Pattern.build(
path,
{ :controller => /.+/ },
- ["/", ".", "?"],
+ SEPARATORS,
false
)
assert_equal(expected, path.to_regexp)
@@ -69,7 +71,7 @@ module ActionDispatch
path = Pattern.build(
path,
{ :controller => /.+/ },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_equal(expected, path.names)
@@ -84,7 +86,7 @@ module ActionDispatch
(tender|love
#MAO
)/x },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_match(path, '/page/tender')
@@ -107,7 +109,7 @@ module ActionDispatch
path = Pattern.build(
'/:name',
{ :name => /\d+/ },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_match(path, '/123')
@@ -118,7 +120,7 @@ module ActionDispatch
path = Pattern.build(
'/page/:name',
{ :name => /(tender|love)/ },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_match(path, '/page/tender')
@@ -131,7 +133,7 @@ module ActionDispatch
path = Pattern.build(
'/page/:name/:value',
requirements,
- ["/", ".", "?"],
+ SEPARATORS,
true
)
@@ -146,7 +148,7 @@ module ActionDispatch
path = Pattern.build(
'/page/:name',
{ :name => /(tender|love)/ },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
match = path.match '/page/tender'
@@ -158,7 +160,7 @@ module ActionDispatch
path = Pattern.build(
'/page/:name/:id',
{ :name => /t(((ender|love)))()/ },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
match = path.match '/page/tender/10'
@@ -173,7 +175,7 @@ module ActionDispatch
path = Pattern.build(
'/page/*foo',
{ :foo => z },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp)
@@ -183,7 +185,7 @@ module ActionDispatch
path = Pattern.build(
'/page/:name/aaron',
{ :name => /(tender|love)/i },
- ["/", ".", "?"],
+ SEPARATORS,
true
)
assert_match(path, '/page/TENDER/aaron')
@@ -192,7 +194,7 @@ module ActionDispatch
end
def test_to_regexp_with_strexp
- path = Pattern.build('/:controller', { }, ["/", ".", "?"], true)
+ path = Pattern.build('/:controller', { }, SEPARATORS, true)
x = %r{\A/([^/.?]+)\Z}
assert_equal(x.source, path.source)
diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb
index cdd59a3316..75e41193b4 100644
--- a/actionpack/test/journey/route_test.rb
+++ b/actionpack/test/journey/route_test.rb
@@ -26,7 +26,7 @@ module ActionDispatch
end
def test_path_requirements_override_defaults
- path = Path::Pattern.build(':name', { name: /love/ }, ['/'], true)
+ path = Path::Pattern.build(':name', { name: /love/ }, '/', true)
defaults = { name: 'tender' }
route = Route.new('name', nil, path, nil, [], defaults)
assert_equal(/love/, route.requirements[:name])