Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
06397336
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
06397336
编写于
1月 20, 2016
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23140 from rails/fix-search-for-custom-routes
Fix marking of custom routes for Journey
上级
24e39ffb
1eace940
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
14 deletion
+83
-14
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+20
-14
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+63
-0
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
06397336
...
...
@@ -184,26 +184,32 @@ def request_method
def
build_path
(
ast
,
requirements
,
anchor
)
pattern
=
Journey
::
Path
::
Pattern
.
new
(
ast
,
requirements
,
JOINED_SEPARATORS
,
anchor
)
# Get all the symbol nodes followed by literals that are not the
# dummy node.
symbols
=
ast
.
find_all
{
|
n
|
n
.
cat?
&&
n
.
left
.
symbol?
&&
n
.
right
.
cat?
&&
n
.
right
.
left
.
literal?
}.
map
(
&
:left
)
# Get all the symbol nodes preceded by literals.
symbols
.
concat
ast
.
find_all
{
|
n
|
n
.
cat?
&&
n
.
left
.
literal?
&&
n
.
right
.
cat?
&&
n
.
right
.
left
.
symbol?
}.
map
{
|
n
|
n
.
right
.
left
}
symbols
.
each
{
|
x
|
x
.
regexp
=
/(?:
#{
Regexp
.
union
(
x
.
regexp
,
'-'
)
}
)+/
# Find all the symbol nodes that are adjacent to literal nodes and alter
# the regexp so that Journey will partition them into custom routes.
ast
.
find_all
{
|
node
|
next
unless
node
.
cat?
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
else
next
end
if
symbol
symbol
.
regexp
=
/(?:
#{
Regexp
.
union
(
symbol
.
regexp
,
'-'
)
}
)+/
end
}
pattern
end
private
:build_path
private
def
add_wildcard_options
(
options
,
formatted
,
path_ast
)
# Add a constraint for wildcard route to make it non-greedy and match the
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
06397336
...
...
@@ -4654,3 +4654,66 @@ def test_legit_routing_not_found_responses
assert_equal
404
,
response
.
status
end
end
class
TestPartialDynamicPathSegments
<
ActionDispatch
::
IntegrationTest
Routes
=
ActionDispatch
::
Routing
::
RouteSet
.
new
Routes
.
draw
do
ok
=
lambda
{
|
env
|
[
200
,
{
'Content-Type'
=>
'text/plain'
},
[]]
}
get
'/songs/song-:song'
,
to:
ok
get
'/songs/:song-song'
,
to:
ok
get
'/:artist/song-:song'
,
to:
ok
get
'/:artist/:song-song'
,
to:
ok
get
'/optional/songs(/song-:song)'
,
to:
ok
get
'/optional/songs(/:song-song)'
,
to:
ok
get
'/optional/:artist(/song-:song)'
,
to:
ok
get
'/optional/:artist(/:song-song)'
,
to:
ok
end
APP
=
build_app
Routes
def
app
APP
end
def
test_paths_with_partial_dynamic_segments_are_recognised
get
'/david-bowie/changes-song'
assert_equal
200
,
response
.
status
assert_params
artist:
'david-bowie'
,
song:
'changes'
get
'/david-bowie/song-changes'
assert_equal
200
,
response
.
status
assert_params
artist:
'david-bowie'
,
song:
'changes'
get
'/songs/song-changes'
assert_equal
200
,
response
.
status
assert_params
song:
'changes'
get
'/songs/changes-song'
assert_equal
200
,
response
.
status
assert_params
song:
'changes'
get
'/optional/songs/song-changes'
assert_equal
200
,
response
.
status
assert_params
song:
'changes'
get
'/optional/songs/changes-song'
assert_equal
200
,
response
.
status
assert_params
song:
'changes'
get
'/optional/david-bowie/changes-song'
assert_equal
200
,
response
.
status
assert_params
artist:
'david-bowie'
,
song:
'changes'
get
'/optional/david-bowie/song-changes'
assert_equal
200
,
response
.
status
assert_params
artist:
'david-bowie'
,
song:
'changes'
end
private
def
assert_params
(
params
)
assert_equal
(
params
,
request
.
path_parameters
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录