Skip to content

Commit 29adfc5

Browse files
committed
Don't modify encoding of argument to unserialize.
Fixes #20
1 parent d191233 commit 29adfc5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/php_serialize.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def PHP.unserialize(string, classmap = nil, assoc = false) # {{{
164164

165165
ret = nil
166166
original_encoding = string.encoding
167-
string = StringIOReader.new(string.force_encoding('BINARY'))
167+
string = StringIOReader.new(string.dup.force_encoding('BINARY'))
168168
while string.string[string.pos, 32] =~ /^(\w+)\|/ # session_name|serialized_data
169169
ret ||= {}
170170
string.pos += $&.size

test/php_serialize_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,14 @@ def test_new_struct_creation
134134
PHP.unserialize(phps)
135135
end
136136
end
137+
138+
def test_encoding_kept
139+
s = String.new('s:3:"abc";', encoding: "ISO-8859-1")
140+
141+
assert_equal "ISO-8859-1", s.encoding.name
142+
143+
PHP.unserialize(s)
144+
145+
assert_equal "ISO-8859-1", s.encoding.name
146+
end
137147
end

0 commit comments

Comments
 (0)