[#35027] [Ruby 1.9-Bug#4352][Open] [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s) — "James M. Lawrence" <redmine@...>

Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

16 messages 2011/02/01

[#35114] [Ruby 1.9-Bug#4373][Open] http.rb:677: [BUG] Segmentation fault — Christian Fazzini <redmine@...>

Bug #4373: http.rb:677: [BUG] Segmentation fault

59 messages 2011/02/06

[#35171] [Ruby 1.9-Bug#4386][Open] encoding: directive does not affect regex expressions — mathew murphy <redmine@...>

Bug #4386: encoding: directive does not affect regex expressions

9 messages 2011/02/09

[#35237] [Ruby 1.9-Bug#4400][Open] nested at_exit hooks run in strange order — Suraj Kurapati <redmine@...>

Bug #4400: nested at_exit hooks run in strange order

12 messages 2011/02/15

[ruby-core:35143] [Ruby 1.9-Bug#4382][Open] Encoding of result string for String#gsub! is not consistent for BINARY

From: Eric Hodel <redmine@...>
Date: 2011-02-07 20:27:04 UTC
List: ruby-core #35143
Bug #4382: Encoding of result string for String#gsub! is not consistent for BINARY
http://redmine.ruby-lang.org/issues/show/4382

Author: Eric Hodel
Status: Open, Priority: Normal
Category: core
ruby -v: ruby 1.9.3dev (2011-02-07 trunk 30814) [x86_64-darwin10.6.0]

When String#sub! is called on a string in BINARY encoding the encoding may be changed to the replacement encoding.

This is due to rb_enc_compatible()

If this is a feature the documentation should be updated to indicate this.

Attached is a test patch.


----------------------------------------
http://redmine.ruby-lang.org

Attachments (1)

test_string.rb.sub_bang_encoding.patch (613 Bytes, text/x-diff)
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 30814)
+++ test/ruby/test_string.rb	(working copy)
@@ -1308,6 +1308,18 @@ class TestString < Test::Unit::TestCase
     assert(a.untrusted?)
   end
 
+  def test_sub_bang_encoding
+    a = S("a")
+    a.force_encoding Encoding::BINARY
+
+    r = ' '
+    r.force_encoding Encoding::UTF_8
+
+    a.sub!(/a/) do r end
+
+    assert_equal Encoding::BINARY, a.encoding
+  end
+
   def test_succ
     assert_equal(S("abd"), S("abc").succ)
     assert_equal(S("z"),   S("y").succ)

In This Thread

Prev Next