Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f75df05f
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,发现更多精彩内容 >>
提交
f75df05f
编写于
5月 24, 2011
作者:
A
Arun Agrawal
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Not loading file if PLATFORM not available.
上级
9dabbd0c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
83 deletion
+82
-83
activesupport/test/xml_mini/jdom_engine_test.rb
activesupport/test/xml_mini/jdom_engine_test.rb
+82
-83
未找到文件。
activesupport/test/xml_mini/jdom_engine_test.rb
浏览文件 @
f75df05f
require
'abstract_unit'
require
'active_support/xml_mini'
require
'active_support/core_ext/hash/conversions'
if
RUBY_PLATFORM
=~
/java/
require
'abstract_unit'
require
'active_support/xml_mini'
require
'active_support/core_ext/hash/conversions'
class
JDOMEngineTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
class
JDOMEngineTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
def
setup
@default_backend
=
XmlMini
.
backend
XmlMini
.
backend
=
'JDOM'
end
def
setup
@default_backend
=
XmlMini
.
backend
XmlMini
.
backend
=
'JDOM'
end
def
teardown
XmlMini
.
backend
=
@default_backend
end
def
teardown
XmlMini
.
backend
=
@default_backend
end
# def test_file_from_xml
# hash = Hash.from_xml(<<-eoxml)
# <blog>
# <logo type="file" name="logo.png" content_type="image/png">
# </logo>
# </blog>
# eoxml
# assert hash.has_key?('blog')
# assert hash['blog'].has_key?('logo')
#
# file = hash['blog']['logo']
# assert_equal 'logo.png', file.original_filename
# assert_equal 'image/png', file.content_type
# end
def
test_exception_thrown_on_expansion_attack
assert_raise
NativeException
do
attack_xml
=
<<-
EOT
# def test_file_from_xml
# hash = Hash.from_xml(<<-eoxml)
# <blog>
# <logo type="file" name="logo.png" content_type="image/png">
# </logo>
# </blog>
# eoxml
# assert hash.has_key?('blog')
# assert hash['blog'].has_key?('logo')
#
# file = hash['blog']['logo']
# assert_equal 'logo.png', file.original_filename
# assert_equal 'image/png', file.content_type
# end
def
test_exception_thrown_on_expansion_attack
assert_raise
NativeException
do
attack_xml
=
<<-
EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
...
...
@@ -47,91 +46,91 @@ def test_exception_thrown_on_expansion_attack
<member>
&a;
</member>
EOT
Hash
.
from_xml
(
attack_xml
)
EOT
Hash
.
from_xml
(
attack_xml
)
end
end
end
def
test_setting_JDOM_as_backend
XmlMini
.
backend
=
'JDOM'
assert_equal
XmlMini_JDOM
,
XmlMini
.
backend
end
def
test_setting_JDOM_as_backend
XmlMini
.
backend
=
'JDOM'
assert_equal
XmlMini_JDOM
,
XmlMini
.
backend
end
def
test_blank_returns_empty_hash
assert_equal
({},
XmlMini
.
parse
(
nil
))
assert_equal
({},
XmlMini
.
parse
(
''
))
end
def
test_blank_returns_empty_hash
assert_equal
({},
XmlMini
.
parse
(
nil
))
assert_equal
({},
XmlMini
.
parse
(
''
))
end
def
test_array_type_makes_an_array
assert_equal_rexml
(
<<-
eoxml
)
def
test_array_type_makes_an_array
assert_equal_rexml
(
<<-
eoxml
)
<blog>
<posts type="array">
<post>a post</post>
<post>another post</post>
</posts>
</blog>
eoxml
end
eoxml
end
def
test_one_node_document_as_hash
assert_equal_rexml
(
<<-
eoxml
)
def
test_one_node_document_as_hash
assert_equal_rexml
(
<<-
eoxml
)
<products/>
eoxml
end
eoxml
end
def
test_one_node_with_attributes_document_as_hash
assert_equal_rexml
(
<<-
eoxml
)
def
test_one_node_with_attributes_document_as_hash
assert_equal_rexml
(
<<-
eoxml
)
<products foo="bar"/>
eoxml
end
eoxml
end
def
test_products_node_with_book_node_as_hash
assert_equal_rexml
(
<<-
eoxml
)
def
test_products_node_with_book_node_as_hash
assert_equal_rexml
(
<<-
eoxml
)
<products>
<book name="awesome" id="12345" />
</products>
eoxml
end
eoxml
end
def
test_products_node_with_two_book_nodes_as_hash
assert_equal_rexml
(
<<-
eoxml
)
def
test_products_node_with_two_book_nodes_as_hash
assert_equal_rexml
(
<<-
eoxml
)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
eoxml
end
eoxml
end
def
test_single_node_with_content_as_hash
assert_equal_rexml
(
<<-
eoxml
)
def
test_single_node_with_content_as_hash
assert_equal_rexml
(
<<-
eoxml
)
<products>
hello world
</products>
eoxml
end
eoxml
end
def
test_children_with_children
assert_equal_rexml
(
<<-
eoxml
)
def
test_children_with_children
assert_equal_rexml
(
<<-
eoxml
)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
eoxml
end
eoxml
end
def
test_children_with_text
assert_equal_rexml
(
<<-
eoxml
)
def
test_children_with_text
assert_equal_rexml
(
<<-
eoxml
)
<root>
<products>
hello everyone
</products>
</root>
eoxml
end
eoxml
end
def
test_children_with_non_adjacent_text
assert_equal_rexml
(
<<-
eoxml
)
def
test_children_with_non_adjacent_text
assert_equal_rexml
(
<<-
eoxml
)
<root>
good
<products>
...
...
@@ -139,15 +138,15 @@ def test_children_with_non_adjacent_text
</products>
morning
</root>
eoxml
end
eoxml
end
private
def
assert_equal_rexml
(
xml
)
hash
=
XmlMini
.
with_backend
(
'REXML'
)
{
XmlMini
.
parse
(
xml
)
}
assert_equal
(
hash
,
XmlMini
.
parse
(
xml
))
private
def
assert_equal_rexml
(
xml
)
hash
=
XmlMini
.
with_backend
(
'REXML'
)
{
XmlMini
.
parse
(
xml
)
}
assert_equal
(
hash
,
XmlMini
.
parse
(
xml
))
end
end
end
else
# don't run these test because we aren't running in JRuby
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录