> I've created a patch against trunk that I believe adds this check and  
> attached it to this message.  Could you please confirm that this patch  
> resolves the regex matching issue you are seeing?
> 
> If anyone sees any problems with this fix, please feel free to point  
> them out.

Thank you for your quick response. In my test rig, your patch makes the
problem go away for operation with 'Telnetmode'=>true (the default).

However the problem is still there if you set 'Telnetmode'=>false in the
client. This is because there's a separate piece of code for this case:

           # Not Telnetmode.
           #
           # We cannot use preprocess() on this data, because that
           # method makes some Telnetmode-specific assumptions.
           buf = c
           buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
           rest = ''

So similar logic is needed to split the string if it ends with \r. The
following seems to work - does it look OK to you?

--- telnet.rb.orig      2008-04-30 11:14:57.000000000 +0100
+++ telnet.rb   2008-04-30 11:22:01.000000000 +0100
@@ -570,14 +570,20 @@
               buf = preprocess(c)
               rest = ''
             end
-         else
+          else
            # Not Telnetmode.
            #
            # We cannot use preprocess() on this data, because that
            # method makes some Telnetmode-specific assumptions.
-           buf = c
-           buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
+           buf = rest + c
            rest = ''
+           unless @options["Binmode"]
+             if pt = buf.rindex(/\r\z/no)
+               buf = buf[0 ... pt]
+               rest = buf[pt .. -1]
+             end
+             buf.gsub!(/#{EOL}/no, "\n")
+           end
           end
           @log.print(buf) if @options.has_key?("Output_log")
           line += buf

Regards,

Brian.