Project

General

Profile

Actions

Bug #7301

closed

URI::FTP.new2()の引数typecodeを省略するとNoMethodErrorが発生します。

Added by shi-mo (Yoshifumi Shimono) about 12 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux]
Backport:
[ruby-dev:46443]

Description

URI::FTP.new2()の引数typecodeを省略するとNoMethodErrorが発生します。


$ cat nil-typecode.rb

encoding: utf-8

require 'uri'

URI::FTP.new2('anonymous', 'anonymous', 'ftp.ubuntu.com', 21, '/')
$ ruby -v nil-typecode.rb
ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux]
/home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/ftp.rb:58:in new2': undefined method size' for nil:NilClass (NoMethodError)
from nil-typecode.rb:5:in `'
$

リファレンスマニュアルの説明(http://doc.okkez.net/static/192/class/URI=3a=3aFTP.html)と関数定義(lib/uri/ftp.rb)を見ると、この引数を省略しても例外は発生すべきでないように思えます。

def self.new2(user, password, host, port, path,
typecode = nil, arg_check = true)


Files

new2_with_typecode.rb (106 Bytes) new2_with_typecode.rb shi-mo (Yoshifumi Shimono), 11/14/2012 07:38 PM

Updated by mame (Yusuke Endoh) about 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to mame (Yusuke Endoh)
  • Target version set to 2.0.0

報告ありがとうございます。
生まれてから 10 年以上このままだったっぽいですね。このメソッド本当に必要なのか?
とりあえず最低限と思われるパッチを入れておきます。

diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index 971684a..6cb9782 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -54,7 +54,7 @@ module URI
# Arguments are user, password, host, port, path, typecode,
# and arg_check, in that order.
def self.new2(user, password, host, port, path,

  •              typecode = nil, arg_check = true)
    
  •              typecode = "", arg_check = true)
     typecode = nil if typecode.size == 0
     if typecode && !TYPECODE.include?(typecode)
       raise ArgumentError,
    

--
Yusuke Endoh

Updated by shi-mo (Yoshifumi Shimono) about 12 years ago

後から気付いたのですが、引数typecodeを与えても例外が発生します。


$ cat new2_with_typecode.rb

encoding: utf-8

require 'uri'

URI::FTP.new2('anonymous', 'anonymous', 'ftp.ubuntu.com', 21, '/', 'a')
$ ruby -v new2_with_typecode.rb
ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux]
/home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/generic.rb:557:in split_userinfo': undefined method split' for ["anonymous", "anonymous"]:Array (NoMethodError)
from /home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/generic.rb:524:in set_userinfo' from /home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/generic.rb:203:in initialize'
from /home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/ftp.rb:140:in initialize' from /home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/ftp.rb:66:in new'
from /home/shimono/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/uri/ftp.rb:66:in new2' from new2_with_typecode.rb:5:in '
$

引数user,passwordの与え方は間違っていないと思うのですが、いかがでしょうか。

Actions #3

Updated by mame (Yusuke Endoh) about 12 years ago

これはダメですね。泥沼化しそうなので、手を入れるべきでないと判断します。

メンテナの YAMADA Akira さん見ていらっしゃいますかね。
返事がなければ、ドキュメントを消して undocumented なメソッドにすることで消極的に解決しようと思います。

--
Yusuke Endoh

Actions #4

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39013.
Yoshifumi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/uri/ftp.rb (URI::FTP.new2): remove the rdoc because it is not
    well tested yet. [Bug #7301]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0