mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 10:03:59 +02:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@33440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
27cec63246
commit
587016b485
3 changed files with 26 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Sep 13 15:02:48 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Sat Oct 8 07:31:42 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* array.c (ary_join_1): should not copy the encoding of non-string
|
* array.c (ary_join_1): should not copy the encoding of non-string
|
||||||
|
|
|
@ -94,10 +94,9 @@ require "thread"
|
||||||
# Needless to say, if you're storing valuable data with PStore, then you should
|
# Needless to say, if you're storing valuable data with PStore, then you should
|
||||||
# backup the PStore files from time to time.
|
# backup the PStore files from time to time.
|
||||||
class PStore
|
class PStore
|
||||||
binmode = defined?(File::BINARY) ? File::BINARY : 0
|
RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
|
||||||
RDWR_ACCESS = File::RDWR | File::CREAT | binmode
|
RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
|
||||||
RD_ACCESS = File::RDONLY | binmode
|
WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
|
||||||
WR_ACCESS = File::WRONLY | File::CREAT | File::TRUNC | binmode
|
|
||||||
|
|
||||||
# The error type thrown by all PStore methods.
|
# The error type thrown by all PStore methods.
|
||||||
class Error < StandardError
|
class Error < StandardError
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'pstore'
|
require 'pstore'
|
||||||
|
require_relative 'ruby/envutil'
|
||||||
|
|
||||||
class PStoreTest < Test::Unit::TestCase
|
class PStoreTest < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
|
@ -110,4 +111,21 @@ class PStoreTest < Test::Unit::TestCase
|
||||||
pstore.transaction { pstore.transaction { } }
|
pstore.transaction { pstore.transaction { } }
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue