sanitize invalid UTF-8 before creating error reports

refs #5638

Change-Id: If469eea015536a8378538fb2fb91cf7725ebdf94
Reviewed-on: https://gerrit.instructure.com/5669
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Cody Cutrer 2011-09-15 13:27:43 -06:00
parent 35127dde5c
commit a913470561
2 changed files with 9 additions and 0 deletions

View File

@ -16,6 +16,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require 'iconv'
class ErrorReport < ActiveRecord::Base
belongs_to :user
belongs_to :account
@ -42,6 +44,9 @@ class ErrorReport < ActiveRecord::Base
def log_error(category, opts)
opts[:category] = category.to_s
@opts = opts
# sanitize invalid encodings
@opts[:message] = Iconv.conv('UTF-8//IGNORE', 'UTF-8', @opts[:message]) if @opts[:message]
@opts[:exception_message] = Iconv.conv('UTF-8//IGNORE', 'UTF-8', @opts[:exception_message]) if @opts[:exception_message]
run_callbacks :on_log_error
create_error_report(opts)
end

View File

@ -47,4 +47,8 @@ describe ErrorReport do
m = Message.last
(!!(m && m.to == "nobody@nowhere.com")).should eql(false)
end
it "should not fail with invalid UTF-8" do
ErrorReport.log_error('my error', :message => "he\xffllo")
end
end