about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-08 05:14:55 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-08 05:23:35 +0000
commit1cd698f8c7938b1f19e9ba091708cb4515187939 (patch)
tree65c8f20247c74e10f65982c6d2d878f37632fd45
parent98c51edf8b6f031a655a93b52808c9f9b78fb6fa (diff)
downloadunicorn-1cd698f8c7938b1f19e9ba091708cb4515187939.tar.gz
Different threads may change $/ during execution, so cache it at
function entry to a local variable for safety.  $/ may also be
of a non-binary encoding, so rely on Rack::Utils.bytesize to
portably capture the correct size.

Our string slicing is always safe from 1.9 encoding: both our
socket and backing temporary file are opened in binary mode,
so we'll always be dealing with binary strings in this class
(in accordance to the Rack spec).
-rw-r--r--lib/unicorn/tee_input.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb
index d1d273d..c0f916e 100644
--- a/lib/unicorn/tee_input.rb
+++ b/lib/unicorn/tee_input.rb
@@ -119,7 +119,7 @@ class Unicorn::TeeInput < Struct.new(:socket, :req, :parser,
   # unlike IO#gets.
   def gets
     socket or return tmp.gets
-    nil == $/ and return read
+    sep = $/ or return read
 
     orig_size = tmp.size
     if tmp.pos == orig_size
@@ -127,8 +127,9 @@ class Unicorn::TeeInput < Struct.new(:socket, :req, :parser,
       tmp.seek(orig_size)
     end
 
+    sep_size = Rack::Utils.bytesize(sep)
     line = tmp.gets # cannot be nil here since size > pos
-    $/ == line[-$/.size, $/.size] and return line
+    sep == line[-sep_size, sep_size] and return line
 
     # unlikely, if we got here, then tmp is at EOF
     begin
@@ -136,7 +137,7 @@ class Unicorn::TeeInput < Struct.new(:socket, :req, :parser,
       tee(@@io_chunk_size, buf2) or break
       tmp.seek(orig_size)
       line << tmp.gets
-      $/ == line[-$/.size, $/.size] and return line
+      sep == line[-sep_size, sep_size] and return line
       # tmp is at EOF again here, retry the loop
     end while true