summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c3
-rw-r--r--test/ruby/test_stringchar.rb50
3 files changed, 58 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8178759b24..9df43f2f05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Nov 19 00:59:31 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (str_gsub): internal buffer should not be listed by
+ ObjectSpace.each_object(). [ruby-dev:24919]
+
Thu Nov 18 23:42:36 2004 Minero Aoki <aamine@loveruby.net>
* ext/ripper/depend: Never regenerate lib/ripper/core.rb
diff --git a/string.c b/string.c
index f388d24db6..efa817ea43 100644
--- a/string.c
+++ b/string.c
@@ -2076,6 +2076,9 @@ str_gsub(argc, argv, str, bang)
blen = RSTRING(str)->len + 30; /* len + margin */
dest = rb_str_new5(str, 0, blen);
+ if (bang) {
+ RBASIC(dest)->klass = 0;
+ }
buf = RSTRING(dest)->ptr;
bp = buf;
sp = cp = RSTRING(str)->ptr;
diff --git a/test/ruby/test_stringchar.rb b/test/ruby/test_stringchar.rb
index 943b656510..34934e87bd 100644
--- a/test/ruby/test_stringchar.rb
+++ b/test/ruby/test_stringchar.rb
@@ -113,4 +113,54 @@ EOS
}
assert_equal(0, a.size)
end
+
+ def test_bang
+ s = "aBc"
+ s.upcase
+ assert_equal("aBc", s)
+ s.upcase!
+ assert_equal("ABC", s)
+
+ s = "aBc"
+ s.downcase
+ assert_equal("aBc", s)
+ s.downcase!
+ assert_equal("abc", s)
+
+ s = "aBc"
+ s.swapcase
+ assert_equal("aBc", s)
+ s.swapcase!
+ assert_equal("AbC", s)
+
+ s = "aBc"
+ s.capitalize
+ assert_equal("aBc", s)
+ s.capitalize!
+ assert_equal("Abc", s)
+
+ s = "aBc"
+ s.tr("a-z", "A-Z")
+ assert_equal("aBc", s)
+ s.tr!("a-z", "A-Z")
+ assert_equal("ABC", s)
+
+ s = "aaBBcc"
+ s.tr_s("a-z", "A-Z")
+ assert_equal("aaBBcc", s)
+ s.tr_s!("a-z", "A-Z")
+ assert_equal("ABBC", s)
+
+ s = "aaBBcc"
+ s.squeeze("a-z")
+ assert_equal("aaBBcc", s)
+ s.squeeze!("a-z")
+ assert_equal("aBBc", s)
+
+ s = "aaBBcc"
+ s.delete("a-z")
+ assert_equal("aaBBcc", s)
+ s.delete!("a-z")
+ assert_equal("BB", s)
+ end
end