Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ac1a5d42
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,发现更多精彩内容 >>
提交
ac1a5d42
编写于
8月 02, 2012
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7129 from kennyj/fix_7079
Improve error handling when using partial name with hyphen. #7079
上级
d8752477
a8d68d89
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
7 deletion
+19
-7
actionpack/lib/action_view/renderer/partial_renderer.rb
actionpack/lib/action_view/renderer/partial_renderer.rb
+12
-7
actionpack/test/template/render_test.rb
actionpack/test/template/render_test.rb
+7
-0
未找到文件。
actionpack/lib/action_view/renderer/partial_renderer.rb
浏览文件 @
ac1a5d42
...
@@ -344,12 +344,6 @@ def setup(context, options, block)
...
@@ -344,12 +344,6 @@ def setup(context, options, block)
paths
.
map!
{
|
path
|
retrieve_variable
(
path
).
unshift
(
path
)
}
paths
.
map!
{
|
path
|
retrieve_variable
(
path
).
unshift
(
path
)
}
end
end
if
String
===
partial
&&
@variable
.
to_s
!~
/^[a-z_][a-zA-Z_0-9]*$/
raise
ArgumentError
.
new
(
"The partial name (
#{
partial
}
) is not a valid Ruby identifier; "
+
"make sure your partial name starts with a lowercase letter or underscore, "
+
"and is followed by any combination of letters, numbers and underscores."
)
end
self
self
end
end
...
@@ -456,8 +450,19 @@ def retrieve_template_keys
...
@@ -456,8 +450,19 @@ def retrieve_template_keys
keys
keys
end
end
IDENTIFIER_ERROR_MESSAGE
=
"The partial name (%s) is not a valid Ruby identifier; "
+
"make sure your partial name starts with a lowercase letter or underscore, "
+
"and is followed by any combination of letters, numbers and underscores."
def
retrieve_variable
(
path
)
def
retrieve_variable
(
path
)
variable
=
@options
.
fetch
(
:as
)
{
path
[
%r'_?(
\w
+)(
\.\w
+)*$'
,
1
]
}.
try
(
:to_sym
)
variable
=
if
as
=
@options
[
:as
]
raise
ArgumentError
.
new
(
IDENTIFIER_ERROR_MESSAGE
%
(
path
))
unless
as
.
to_s
=~
/\A[a-z_]\w*\z/
as
.
to_sym
else
base
=
path
[
-
1
]
==
"/"
?
""
:
File
.
basename
(
path
)
raise
ArgumentError
.
new
(
IDENTIFIER_ERROR_MESSAGE
%
(
path
))
unless
base
=~
/\A_?([a-z]\w*)(\.\w+)*\z/
$1
.
to_sym
end
variable_counter
=
:"
#{
variable
}
_counter"
if
@collection
variable_counter
=
:"
#{
variable
}
_counter"
if
@collection
[
variable
,
variable_counter
]
[
variable
,
variable_counter
]
end
end
...
...
actionpack/test/template/render_test.rb
浏览文件 @
ac1a5d42
...
@@ -187,6 +187,13 @@ def test_render_partial_with_incompatible_object
...
@@ -187,6 +187,13 @@ def test_render_partial_with_incompatible_object
assert_equal
"'
#{
nil
.
inspect
}
' is not an ActiveModel-compatible object. It must implement :to_partial_path."
,
e
.
message
assert_equal
"'
#{
nil
.
inspect
}
' is not an ActiveModel-compatible object. It must implement :to_partial_path."
,
e
.
message
end
end
def
test_render_partial_with_hyphen
e
=
assert_raises
(
ArgumentError
)
{
@view
.
render
(
:partial
=>
"test/a-in"
)
}
assert_equal
"The partial name (test/a-in) is not a valid Ruby identifier; "
+
"make sure your partial name starts with a lowercase letter or underscore, "
+
"and is followed by any combination of letters, numbers and underscores."
,
e
.
message
end
def
test_render_partial_with_errors
def
test_render_partial_with_errors
e
=
assert_raises
(
ActionView
::
Template
::
Error
)
{
@view
.
render
(
:partial
=>
"test/raise"
)
}
e
=
assert_raises
(
ActionView
::
Template
::
Error
)
{
@view
.
render
(
:partial
=>
"test/raise"
)
}
assert_match
%r!method.*doesnt_exist!
,
e
.
message
assert_match
%r!method.*doesnt_exist!
,
e
.
message
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录