Bug #7301

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

Added by Yoshifumi Shimono over 1 year ago. Updated about 1 year ago.

[ruby-dev:46443]
Status:Closed
Priority:Normal
Assignee:Yusuke Endoh
Category:-
Target version:2.0.0
ruby -v:ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux] Backport:

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 methodsize' 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)

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

Associated revisions

Revision 39013
Added by Yusuke Endoh about 1 year ago

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

Revision 39014
Added by Zachary Scott about 1 year ago

  • lib/uri/ftp.rb (URI::FTP.new2): nodoc method from r39013 [Bug #7301]

History

#1 Updated by Yusuke Endoh over 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to 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 argcheck, 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 mame@tsg.ne.jp

#2 Updated by Yoshifumi Shimono over 1 year ago

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


$ cat new2withtypecode.rb

encoding: utf-8

require 'uri'

URI::FTP.new2('anonymous', 'anonymous', 'ftp.ubuntu.com', 21, '/', 'a')
$ ruby -v new2withtypecode.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 methodsplit' 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の与え方は間違っていないと思うのですが、いかがでしょうか。

#3 Updated by Yusuke Endoh over 1 year ago

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

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

Yusuke Endoh mame@tsg.ne.jp

#4 Updated by Yusuke Endoh about 1 year 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]

Also available in: Atom PDF