From a438fce7e349c38fc9d0136da79806c2adf357ba Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 7 Aug 2010 04:59:27 +0000 Subject: * ext/pathname/pathname.c (path_sub_ext): don't clobber shared string. [ruby-core:31640] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/pathname/pathname.c | 2 +- test/pathname/test_pathname.rb | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5de296d47..1578877da5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Aug 7 13:59:19 2010 Nobuyoshi Nakada + + * ext/pathname/pathname.c (path_sub_ext): don't clobber shared string. + [ruby-core:31640] + Sat Aug 7 13:33:25 2010 Nobuyoshi Nakada * vm_eval.c (vm_call0): fix for VM_METHOD_TYPE_NOTIMPLEMENTED. diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index d62cbdd83e..5dc846a2ed 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -192,7 +192,7 @@ path_sub_ext(VALUE self, VALUE repl) ext += extlen; } str2 = rb_str_dup(str); - rb_str_set_len(str2, ext-p); + rb_str_resize(str2, ext-p); rb_str_append(str2, repl); OBJ_INFECT(str2, str); return rb_class_new_instance(1, &str2, rb_obj_class(self)); diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 94bcffafbd..eb42aab122 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -19,7 +19,10 @@ class TestPathname < Test::Unit::TestCase def self.defassert(name, result, *args) define_assertion(name) { - assert_equal(result, self.send(name, *args), "#{name}(#{args.map {|a| a.inspect }.join(', ')})") + mesg = "#{name}(#{args.map {|a| a.inspect }.join(', ')})" + assert_nothing_raised(mesg) { + assert_equal(result, self.send(name, *args), mesg) + } } end @@ -506,6 +509,7 @@ class TestPathname < Test::Unit::TestCase defassert(:pathsubext, 'lex.yy.o', 'lex.yy.c', '.o') defassert(:pathsubext, 'fooaa.o', 'fooaa', '.o') defassert(:pathsubext, 'd.e/aa.o', 'd.e/aa', '.o') + defassert(:pathsubext, 'long_enough.bug-3664', 'long_enough.not_to_be_embeded[ruby-core:31640]', '.bug-3664') def test_sub_matchdata result = Pathname("abc.gif").sub(/\..*/) { -- cgit v1.2.3