提交 d6859a72 编写于 作者: D David Heinemeier Hansson

Add tests for html_escape, and remove an unneeded backslash (closes #10511) [fxn]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8422 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 56e64629
......@@ -5,7 +5,7 @@ module Util
HTML_ESCAPE = { '&' => '&amp;', '"' => '&quot;', '>' => '&gt;', '<' => '&lt;' }
def html_escape(s)
s.to_s.gsub(/[&\"><]/) { |special| HTML_ESCAPE[special] }
s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
end
end
end
......
require "#{File.dirname(__FILE__)}/../abstract_unit"
class ErbUtilTest < Test::Unit::TestCase
include ERB::Util
def test_amp
assert_equal '&amp;', html_escape('&')
end
def test_quot
assert_equal '&quot;', html_escape('"')
end
def test_lt
assert_equal '&lt;', html_escape('<')
end
def test_gt
assert_equal '&gt;', html_escape('>')
end
def test_rest_in_ascii
(0..127).to_a.map(&:chr).each do |chr|
next if %w(& " < >).include?(chr)
assert_equal chr, html_escape(chr)
end
end
end
require "#{File.dirname(__FILE__)}/../abstract_unit"
class ErbUtilTest < Test::Unit::TestCase
include ERB::Util
def test_amp
assert_equal '&amp;', html_escape('&')
end
def test_quot
assert_equal '&quot;', html_escape('"')
end
def test_lt
assert_equal '&lt;', html_escape('<')
end
def test_gt
assert_equal '&gt;', html_escape('>')
end
def test_rest_in_ascii
(0..127).to_a.map(&:chr).each do |chr|
next if %w(& " < >).include?(chr)
assert_equal chr, html_escape(chr)
end
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册