fix for a ruby 1.9 warning message

Backported from ruby 2.0 (and possibly later 1.9 patchlevels) because it
was filling our logs with many millions of warnings. The code was
backported directly, the test was backported with conversion from
minitest -> rspec.

test plan: Delayed jobs that use ruby's net libraries should still work,
such as sending messages, taking web snapshots, etc. You shouldn't see
any further lines like this in the log:

net/protocol.rb:313: warning: regexp match /.../n against to UTF-8 string

Change-Id: Ic29daa4ee9f0587fb2a1ac2968cd08a2f68365a1
Reviewed-on: https://gerrit.instructure.com/17431
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
QA-Review: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Brian Palmer 2013-02-04 14:58:38 -07:00
parent f72c6c599d
commit d7bac4a190
3 changed files with 47 additions and 0 deletions

View File

@ -144,4 +144,18 @@ else
super.force_encoding('utf-8')
end
end
# Fix for https://bugs.ruby-lang.org/issues/7278 , which was filling up our logs with these warnings
if RUBY_VERSION < "2."
require 'net/protocol'
class Net::InternetMessageIO
def each_crlf_line(src)
buffer_filling(@wbuf, src) do
while line = @wbuf.slice!(/\A[^\r\n]*(?:\n|\r(?:\n|(?!\z)))/)
yield line.chomp("\n") + "\r\n"
end
end
end
end
end
end

View File

@ -0,0 +1,23 @@
require File.expand_path('../spec_helper', File.dirname( __FILE__ ))
describe 'ruby_version_compat' do
describe 'backport of ruby #7278' do
it "should not output to stdout/stderr" do
pending("ruby 1.9+ only") if RUBY_VERSION < "1.9."
output = capture_io do
sio = StringIO.new("")
imio = Net::InternetMessageIO.new(sio)
imio.write_message("\u3042\r\u3044\n\u3046\r\n\u3048").should == 23
sio.string.should == "\u3042\r\n\u3044\r\n\u3046\r\n\u3048\r\n.\r\n".force_encoding('us-ascii')
sio = StringIO.new("")
imio = Net::InternetMessageIO.new(sio)
imio.write_message("\u3042\r").should == 8
sio.string.should == "\u3042\r\n.\r\n".force_encoding('us-ascii')
end
output.should == ['', '']
end
end
end

View File

@ -864,6 +864,16 @@ Spec::Runner.configure do |config|
str
end
# from minitest, MIT licensed
def capture_io
orig_stdout, orig_stderr = $stdout, $stderr
$stdout, $stderr = StringIO.new, StringIO.new
yield
return $stdout.string, $stderr.string
ensure
$stdout, $stderr = orig_stdout, orig_stderr
end
def verify_post_matches(post_lines, expected_post_lines)
# first lines should match
post_lines[0].should == expected_post_lines[0]