mirror of
https://github.com/github/rails.git
synced 2026-01-31 01:08:19 -05:00
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
This commit is contained in:
@@ -5,7 +5,7 @@ class ERB
|
||||
HTML_ESCAPE = { '&' => '&', '"' => '"', '>' => '>', '<' => '<' }
|
||||
|
||||
def html_escape(s)
|
||||
s.to_s.gsub(/[&\"><]/) { |special| HTML_ESCAPE[special] }
|
||||
s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
56
actionpack/test/template/erb_util_test.rb
Normal file
56
actionpack/test/template/erb_util_test.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
||||
|
||||
class ErbUtilTest < Test::Unit::TestCase
|
||||
include ERB::Util
|
||||
|
||||
def test_amp
|
||||
assert_equal '&', html_escape('&')
|
||||
end
|
||||
|
||||
def test_quot
|
||||
assert_equal '"', html_escape('"')
|
||||
end
|
||||
|
||||
def test_lt
|
||||
assert_equal '<', html_escape('<')
|
||||
end
|
||||
|
||||
def test_gt
|
||||
assert_equal '>', 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 '&', html_escape('&')
|
||||
end
|
||||
|
||||
def test_quot
|
||||
assert_equal '"', html_escape('"')
|
||||
end
|
||||
|
||||
def test_lt
|
||||
assert_equal '<', html_escape('<')
|
||||
end
|
||||
|
||||
def test_gt
|
||||
assert_equal '>', 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
|
||||
Reference in New Issue
Block a user