Project

General

Profile

Backport #1850

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

=begin 
  
  When Net::FTP#login is invoked giving a not nil password, and a user different from "anonymous" the following error is raised: TypeError.new("can't convert nil into String")  
 
  This happens due to the fact that in lib/net/ftp.rb (line 381) password is concatenated with a string, without cheking first if it is nil. 
 
  The error can be reproduced this way: 
 
  [1] Simple (wrong) use of Net::FTP#login 
  ======================================== 
 
  ftp=Net::FTP.new "petra.euitio.uniovi.es" 
  ftp.login "i1650878" 
 
  Error stack trace 
  ================= 
  TypeError: can't convert nil into String 
          from /usr/lib/ruby/1.8/net/ftp.rb:381:in `+' 
          from /usr/lib/ruby/1.8/net/ftp.rb:381:in `login' 
          from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
          from /usr/lib/ruby/1.8/net/ftp.rb:378:in `login' 
          from (irb):7 
          from :0 
 
  Although the error is somehow easy to discover its meaning is not directly related with the use of Net::FTP#login method. What's more, if Net::FTP#login is used from a higher level API, it's quite difficult to figure out what's happening without getting deep into the code (See[2]). In my humble opinion, it shouldn't be Net::FTP users' concern if nil can't be concateneted with a String. I think this should be a contract that the own method has to provide by means of a precondition.  
 
 
  [2] - Not so wrong use of Net::FTP#login from Kernel#open in lib/open-uri.rb: 
  ============================================================================ 
  require 'open-uri' 
  open('ftp://i1891823@petra.euitio.uniovi.es/home/alumnos/i1891823/csv.txt') 
 
 
  Error stack trace 
  ================= 
  TypeError: can't convert nil into String 
          from /usr/lib/ruby/1.8/net/ftp.rb:381:in `+' 
          from /usr/lib/ruby/1.8/net/ftp.rb:381:in `login' 
          from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
          from /usr/lib/ruby/1.8/net/ftp.rb:378:in `login' 
          from /usr/lib/ruby/1.8/open-uri.rb:657:in `buffer_open' 
          from /usr/lib/ruby/1.8/open-uri.rb:164:in `open_loop' 
          from /usr/lib/ruby/1.8/open-uri.rb:162:in `catch' 
          from /usr/lib/ruby/1.8/open-uri.rb:162:in `open_loop' 
          from /usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri' 
          from /usr/lib/ruby/1.8/open-uri.rb:518:in `open' 
          from /usr/lib/ruby/1.8/open-uri.rb:30:in `open' 
          from (irb):14 
 
 =end 
 

Back