Skip to content

Commit 879ee6e

Browse files
authored
Merge pull request rails#41099 from jhawthorn/router_optional_part_of_segment
Fix issue routing with optional parts of a segment
2 parents 05dc13f + c933b06 commit 879ee6e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

actionpack/lib/action_dispatch/journey/path/pattern.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def requirements_anchored?
4545

4646
terminals.each_with_index { |s, index|
4747
next if index < 1
48-
next unless s.symbol?
48+
next if s.type == :DOT || s.type == :SLASH
4949

5050
back = terminals[index - 1]
5151
fwd = terminals[index + 1]
5252

5353
# we also don't support this yet, constraints must be regexps
54-
return false if s.regexp.is_a?(Array)
54+
return false if s.symbol? && s.regexp.is_a?(Array)
5555

5656
return false if back.literal?
5757
return false if !fwd.nil? && fwd.literal?

actionpack/test/dispatch/routing_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,18 @@ def test_optional_scoped_root_multiple_choice
14591459
assert_equal "projects#index", @response.body
14601460
end
14611461

1462+
def test_optional_part_of_segment
1463+
draw do
1464+
get "/star-trek(-tng)/:episode", to: "star_trek#show"
1465+
end
1466+
1467+
get "/star-trek/02-15-the-trouble-with-tribbles"
1468+
assert_equal "star_trek#show", @response.body
1469+
1470+
get "/star-trek-tng/05-02-darmok"
1471+
assert_equal "star_trek#show", @response.body
1472+
end
1473+
14621474
def test_scope_with_format_option
14631475
draw do
14641476
get "direct/index", as: :no_format_direct, format: false

0 commit comments

Comments
 (0)