Skip to content

Commit

Permalink
fixing utf8 escape vulerability
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Aug 16, 2011
1 parent 60f783d commit e0774e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -19,7 +19,7 @@ def html_escape(s)
if s.html_safe?
s
else
s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }.html_safe
s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;").html_safe
end
end

Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/core_ext/string_ext_test.rb
Expand Up @@ -2,10 +2,17 @@
require 'date'
require 'abstract_unit'
require 'inflector_test_cases'
require 'active_support/core_ext/string/output_safety'

class StringInflectionsTest < Test::Unit::TestCase
include InflectorTestCases

def test_erb_escape
string = [192, 60].pack('CC')
expected = 192.chr + "&lt;"
assert_equal expected, ERB::Util.html_escape(string)
end

def test_pluralize
SingularToPlural.each do |singular, plural|
assert_equal(plural, singular.pluralize)
Expand Down

0 comments on commit e0774e4

Please sign in to comment.