From 60d4fc9f68c16099a9d9574ebea599b084a4a237 Mon Sep 17 00:00:00 2001 From: kazu Date: Wed, 2 Apr 2014 02:51:20 +0000 Subject: [PATCH] Fix error with empty args. * ext/pathname/lib/pathname.rb (Pathname#join): Fix error with empty args. Reported by ko1 via IRC. * test/pathname/test_pathname.rb (TestPathname#test_join): Add the test for above case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ ext/pathname/lib/pathname.rb | 1 + test/pathname/test_pathname.rb | 2 ++ 3 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index ee351fa51a..cad30526c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Apr 2 11:46:29 2014 Kazuhiro NISHIYAMA + + * ext/pathname/lib/pathname.rb (Pathname#join): Fix error with + empty args. Reported by ko1 via IRC. + + * test/pathname/test_pathname.rb (TestPathname#test_join): Add the + test for above case. + Tue Apr 1 11:39:57 2014 James Edward Gray II * lib/csv.rb: Symbol HeaderConverter: strip leading/trailing space. diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index bbcb5e4e2a..aa9464799d 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -384,6 +384,7 @@ class Pathname # #=> true # def join(*args) + return self if args.empty? result = args.pop result = Pathname.new(result) unless Pathname === result return result if result.absolute? diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 94bd8d8872..4e88db754d 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -242,6 +242,8 @@ class TestPathname < Test::Unit::TestCase assert_equal(Pathname("/c"), r) r = Pathname("/a").join("/b", "/c") assert_equal(Pathname("/c"), r) + r = Pathname("/foo/var").join() + assert_equal(Pathname("/foo/var"), r) end def test_absolute