ruby-changes:21215
From: nobu <ko1@a...>
Date: Tue, 13 Sep 2011 15:03:47 +0900 (JST)
Subject: [ruby-changes:21215] nobu:r33264 (trunk): * lib/pstore.rb (PStore): always open in binary mode even if
nobu 2011-09-13 15:02:59 +0900 (Tue, 13 Sep 2011) New Revision: 33264 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33264 Log: * lib/pstore.rb (PStore): always open in binary mode even if default encodings are set. [Bug #5311] [ruby-core:39503] Modified files: trunk/ChangeLog trunk/lib/pstore.rb trunk/test/test_pstore.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33263) +++ ChangeLog (revision 33264) @@ -1,3 +1,8 @@ +Tue Sep 13 15:02:48 2011 Nobuyoshi Nakada <nobu@r...> + + * lib/pstore.rb (PStore): always open in binary mode even if + default encodings are set. [Bug #5311] [ruby-core:39503] + Tue Sep 13 05:37:15 2011 Yukihiro Matsumoto <matz@r...> * io.c (Init_IO): update BINARY comment. it should not change the Index: lib/pstore.rb =================================================================== --- lib/pstore.rb (revision 33263) +++ lib/pstore.rb (revision 33264) @@ -94,10 +94,9 @@ # Needless to say, if you're storing valuable data with PStore, then you should # backup the PStore files from time to time. class PStore - binmode = defined?(File::BINARY) ? File::BINARY : 0 - RDWR_ACCESS = File::RDWR | File::CREAT | binmode - RD_ACCESS = File::RDONLY | binmode - WR_ACCESS = File::WRONLY | File::CREAT | File::TRUNC | binmode + RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze + RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze + WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze # The error type thrown by all PStore methods. class Error < StandardError Index: test/test_pstore.rb =================================================================== --- test/test_pstore.rb (revision 33263) +++ test/test_pstore.rb (revision 33264) @@ -1,5 +1,6 @@ require 'test/unit' require 'pstore' +require_relative 'ruby/envutil' class PStoreTest < Test::Unit::TestCase def setup @@ -110,4 +111,21 @@ pstore.transaction { pstore.transaction { } } end end + + # Test that PStore's file operations do not blow up when default encodings are set + def test_pstore_files_are_accessed_as_binary_files + bug5311 = '[ruby-core:39503]' + n = 128 + assert_in_out_err(["-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311) + @pstore = PStore.new(ARGV[0]) + Encoding.default_internal = 'utf-8' + Encoding.default_external = 'utf-8' + (1..#{n}).each do |i| + @pstore.transaction {@pstore["Key\#{i}"] = "value \#{i}"} + end + @pstore.transaction {@pstore["Bug5311"] = '#{bug5311}'} + puts @pstore.transaction {@pstore["Bug5311"]} + SRC + assert_equal(bug5311, @pstore.transaction {@pstore["Bug5311"]}, bug5311) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/