Permalink
Browse files

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
  • Loading branch information...
1 parent 56e6462 commit d6859a7216fbe40f523fd80f85a06fa3e23070bb @dhh dhh committed Dec 16, 2007
Showing with 57 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_view/template_handlers/erb.rb
  2. +56 −0 actionpack/test/template/erb_util_test.rb
@@ -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
@@ -0,0 +1,56 @@
+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

0 comments on commit d6859a7

Please sign in to comment.