[前][次][番号順一覧][スレッド一覧]

ruby-changes:21391

From: yugui <ko1@a...>
Date: Sun, 9 Oct 2011 22:18:52 +0900 (JST)
Subject: [ruby-changes:21391] yugui:r33440 (ruby_1_9_3): merges r33264 from trunk into ruby_1_9_3.

yugui	2011-10-09 22:15:12 +0900 (Sun, 09 Oct 2011)

  New Revision: 33440

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33440

  Log:
    merges r33264 from trunk into ruby_1_9_3.
    --
    * lib/pstore.rb (PStore): always open in binary mode even if
      default encodings are set.  [Bug #5311] [ruby-core:39503]

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/lib/pstore.rb
    branches/ruby_1_9_3/test/test_pstore.rb

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 33439)
+++ ruby_1_9_3/ChangeLog	(revision 33440)
@@ -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]
+
 Sat Oct  8 07:31:42 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* array.c (ary_join_1): should not copy the encoding of non-string
Index: ruby_1_9_3/lib/pstore.rb
===================================================================
--- ruby_1_9_3/lib/pstore.rb	(revision 33439)
+++ ruby_1_9_3/lib/pstore.rb	(revision 33440)
@@ -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: ruby_1_9_3/test/test_pstore.rb
===================================================================
--- ruby_1_9_3/test/test_pstore.rb	(revision 33439)
+++ ruby_1_9_3/test/test_pstore.rb	(revision 33440)
@@ -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/

[前][次][番号順一覧][スレッド一覧]