Skip to content

Commit 1932359

Browse files
authored
Merge pull request rails#53453 from rails/rm-fix-double-colon-routes
Fix routes with `::` in the path
2 parents d1dc4dd + 902d99c commit 1932359

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

actionpack/lib/action_dispatch/journey/scanner.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def last_literal
5555
def scan
5656
next_byte = @scanner.peek_byte
5757
case
58-
when (token = STATIC_TOKENS[next_byte])
58+
when (token = STATIC_TOKENS[next_byte]) && (token != :SYMBOL || next_byte_is_not_a_token?)
5959
@scanner.pos += 1
6060
@length = @scanner.skip(/\w+/).to_i + 1 if token == :SYMBOL || token == :STAR
6161
token
@@ -65,6 +65,10 @@ def scan
6565
:LITERAL
6666
end
6767
end
68+
69+
def next_byte_is_not_a_token?
70+
!STATIC_TOKENS[@scanner.string.getbyte(@scanner.pos + 1)]
71+
end
6872
end
6973
end
7074
end

actionpack/test/dispatch/routing_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,16 @@ def test_nested_routes_under_format_resource
39243924
assert_equal "/formats/1/items/2.json", format_item_path(1, 2, :json)
39253925
end
39263926

3927+
def test_routes_with_double_colon
3928+
draw do
3929+
get "/sort::sort", to: "sessions#sort"
3930+
end
3931+
3932+
get "/sort:asc"
3933+
assert_equal "asc", @request.params[:sort]
3934+
assert_equal "sessions#sort", @response.body
3935+
end
3936+
39273937
private
39283938
def draw(&block)
39293939
self.class.stub_controllers do |routes|

actionpack/test/journey/route/definition/scanner_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def setup
6060
:SYMBOL,
6161
:RPAREN,
6262
]],
63+
["/sort::sort", [
64+
:SLASH,
65+
:LITERAL,
66+
:LITERAL,
67+
:SYMBOL
68+
]],
6369
]
6470

6571
CASES.each do |pattern, expected_tokens|

0 commit comments

Comments
 (0)