php-serialize 1.3.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/php_serialize.rb +15 -8
- data/test/php_serialize_test.rb +30 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0591bd5488ad85fe41df67a598114a16443c7ff275d3ccbaeadc1a02e2a8868b'
|
4
|
+
data.tar.gz: afa368fe56e55dec820f09925910a447e01e51fe791ddee35d55fd4421b441d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eec063376173d5b74cda2dd5e46352093973e64f21936f3d3b4d66de532aafe2c4928ab921db008221de178ece92960315418b6b19db8114bfe0a4c4e1c9637e
|
7
|
+
data.tar.gz: b9774ec8c8edf352cd12a74142785cdc2804bd19437f586decacbc7f41a72d8cff719c8985978c65c97b3735168ffaee305a7779b9e920ad5dd9819fbb681199
|
data/lib/php_serialize.rb
CHANGED
@@ -163,19 +163,20 @@ module PHP
|
|
163
163
|
classmap ||= {}
|
164
164
|
|
165
165
|
ret = nil
|
166
|
-
|
166
|
+
original_encoding = string.encoding
|
167
|
+
string = StringIOReader.new(string.dup.force_encoding('BINARY'))
|
167
168
|
while string.string[string.pos, 32] =~ /^(\w+)\|/ # session_name|serialized_data
|
168
169
|
ret ||= {}
|
169
170
|
string.pos += $&.size
|
170
|
-
ret[$1] = PHP.do_unserialize(string, classmap, assoc)
|
171
|
+
ret[$1] = PHP.do_unserialize(string, classmap, assoc, original_encoding)
|
171
172
|
end
|
172
173
|
|
173
|
-
ret || PHP.do_unserialize(string, classmap, assoc)
|
174
|
+
ret || PHP.do_unserialize(string, classmap, assoc, original_encoding)
|
174
175
|
end
|
175
176
|
|
176
177
|
private
|
177
178
|
|
178
|
-
def PHP.do_unserialize(string, classmap, assoc)
|
179
|
+
def PHP.do_unserialize(string, classmap, assoc, original_encoding)
|
179
180
|
val = nil
|
180
181
|
# determine a type
|
181
182
|
type = string.read(2)[0,1]
|
@@ -184,7 +185,7 @@ module PHP
|
|
184
185
|
count = string.read_until('{').to_i
|
185
186
|
val = Array.new
|
186
187
|
count.times do |i|
|
187
|
-
val << [do_unserialize(string, classmap, assoc), do_unserialize(string, classmap, assoc)]
|
188
|
+
val << [do_unserialize(string, classmap, assoc, original_encoding), do_unserialize(string, classmap, assoc, original_encoding)]
|
188
189
|
end
|
189
190
|
string.read(1) # skip the ending }
|
190
191
|
|
@@ -200,6 +201,12 @@ module PHP
|
|
200
201
|
i += 1
|
201
202
|
end
|
202
203
|
|
204
|
+
val = val.map { |tuple|
|
205
|
+
tuple.map { |it|
|
206
|
+
it.kind_of?(String) ? it.force_encoding(original_encoding) : it
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
203
210
|
if array
|
204
211
|
val.map! {|_,value| value }
|
205
212
|
elsif !assoc
|
@@ -216,8 +223,8 @@ module PHP
|
|
216
223
|
len = string.read_until('{').to_i
|
217
224
|
|
218
225
|
len.times do
|
219
|
-
attr = (do_unserialize(string, classmap, assoc))
|
220
|
-
attrs << [attr.intern, (attr << '=').intern, do_unserialize(string, classmap, assoc)]
|
226
|
+
attr = (do_unserialize(string, classmap, assoc, original_encoding))
|
227
|
+
attrs << [attr.intern, (attr << '=').intern, do_unserialize(string, classmap, assoc, original_encoding)]
|
221
228
|
end
|
222
229
|
string.read(1)
|
223
230
|
|
@@ -245,7 +252,7 @@ module PHP
|
|
245
252
|
|
246
253
|
when 's' # string, s:length:"data";
|
247
254
|
len = string.read_until(':').to_i + 3 # quotes, separator
|
248
|
-
val = string.read(len)[1...-2] # read it, kill useless quotes
|
255
|
+
val = string.read(len)[1...-2].force_encoding(original_encoding) # read it, kill useless quotes
|
249
256
|
|
250
257
|
when 'i' # integer, i:123
|
251
258
|
val = string.read_until(';').to_i
|
data/test/php_serialize_test.rb
CHANGED
@@ -76,7 +76,9 @@ class TestPhpSerialize < Test::Unit::TestCase
|
|
76
76
|
# PHP counts multibyte string, not string length
|
77
77
|
def test_multibyte_string
|
78
78
|
assert_equal "s:6:\"öäü\";", PHP.serialize("öäü")
|
79
|
+
assert_equal PHP.unserialize("s:6:\"öäü\";"), "öäü"
|
79
80
|
end
|
81
|
+
|
80
82
|
# Verify assoc is passed down calls.
|
81
83
|
# Slightly awkward because hashes don't guarantee order.
|
82
84
|
def test_assoc
|
@@ -94,6 +96,24 @@ class TestPhpSerialize < Test::Unit::TestCase
|
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
99
|
+
# Multibyte version.
|
100
|
+
# Verify assoc is passed down calls.
|
101
|
+
# Slightly awkward because hashes don't guarantee order.
|
102
|
+
def test_assoc_multibyte
|
103
|
+
assert_nothing_raised do
|
104
|
+
ruby = {'ああ' => ['öäü','漢字'], 'hash' => {'おはよう' => 'smoke'}}
|
105
|
+
ruby_assoc = [['ああ', ['öäü','漢字']], ['hash', [['おはよう','smoke']]]]
|
106
|
+
phps = [
|
107
|
+
'a:2:{s:6:"ああ";a:2:{i:0;s:6:"öäü";i:1;s:6:"漢字";}s:4:"hash";a:1:{s:12:"おはよう";s:5:"smoke";}}',
|
108
|
+
'a:2:{s:4:"hash";a:1:{s:12:"おはよう";s:5:"smoke";}s:6:"ああ";a:2:{i:0;s:6:"öäü";i:1;s:6:"漢字";}}'
|
109
|
+
]
|
110
|
+
serialized = PHP.serialize(ruby, true)
|
111
|
+
assert phps.include?(serialized)
|
112
|
+
unserialized = PHP.unserialize(serialized, true)
|
113
|
+
assert_equal ruby_assoc.sort, unserialized.sort
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
97
117
|
def test_sessions
|
98
118
|
assert_nothing_raised do
|
99
119
|
ruby = {'session_id' => 42, 'user_data' => {'uid' => 666}}
|
@@ -114,4 +134,14 @@ class TestPhpSerialize < Test::Unit::TestCase
|
|
114
134
|
PHP.unserialize(phps)
|
115
135
|
end
|
116
136
|
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
|
117
147
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: php-serialize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hurst
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,7 @@ homepage: https://github.com/jqr/php-serialize
|
|
53
53
|
licenses:
|
54
54
|
- MIT
|
55
55
|
metadata: {}
|
56
|
-
post_install_message:
|
56
|
+
post_install_message:
|
57
57
|
rdoc_options: []
|
58
58
|
require_paths:
|
59
59
|
- lib/
|
@@ -68,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
71
|
+
rubygems_version: 3.4.19
|
72
|
+
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: Ruby analogs to PHP's serialize() and unserialize() functions
|
75
75
|
test_files:
|