php-serialization 0.4.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -7
- data/VERSION +1 -1
- data/lib/php_serialization/serializer.rb +8 -3
- data/lib/php_serialization/unserializer.rb +85 -91
- data/lib/php_serialization/unserializer.y +16 -16
- data/lib/php_serialization.rb +1 -1
- data/php-serialization.gemspec +6 -5
- data/spec/serialization_spec.rb +3 -3
- data/spec/session_serialization_spec.rb +1 -1
- data/spec/unserialization_spec.rb +5 -6
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -13,11 +13,11 @@ Primitive values
|
|
13
13
|
|
14
14
|
Array
|
15
15
|
|
16
|
-
PhpSerialization.dump([true, "foo"]) # => "a:2:{i:0;b:1;i:1;s:3:\"foo\";}
|
16
|
+
PhpSerialization.dump([true, "foo"]) # => "a:2:{i:0;b:1;i:1;s:3:\"foo\";}"
|
17
17
|
|
18
18
|
Hash
|
19
19
|
|
20
|
-
PhpSerialization.dump("name" => "Rodrigo", "age" => 23) # => "a:2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}
|
20
|
+
PhpSerialization.dump("name" => "Rodrigo", "age" => 23) # => "a:2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}"
|
21
21
|
|
22
22
|
Object
|
23
23
|
|
@@ -29,7 +29,7 @@ Object
|
|
29
29
|
person.name = "Rodrigo"
|
30
30
|
person.age = 23
|
31
31
|
|
32
|
-
PhpSerialization.dump(person) # => "O:6:\"Person\":2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}
|
32
|
+
PhpSerialization.dump(person) # => "O:6:\"Person\":2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}"
|
33
33
|
|
34
34
|
== Unserialization examples
|
35
35
|
|
@@ -42,11 +42,11 @@ Primitive values
|
|
42
42
|
|
43
43
|
Array
|
44
44
|
|
45
|
-
PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";}
|
45
|
+
PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";}') # => [true, "foo"]
|
46
46
|
|
47
47
|
Hash
|
48
48
|
|
49
|
-
PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
49
|
+
PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}') # => {"name" => "Rodrigo", "age" => 23}
|
50
50
|
|
51
51
|
Object
|
52
52
|
|
@@ -54,13 +54,13 @@ Object
|
|
54
54
|
attr_accessor :name, :age
|
55
55
|
end
|
56
56
|
|
57
|
-
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
57
|
+
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
58
58
|
person.name # => "Rodrigo"
|
59
59
|
person.age # => 23
|
60
60
|
|
61
61
|
Object without class will map to a Struct
|
62
62
|
|
63
|
-
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
63
|
+
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
64
64
|
person.class # => Struct::Person
|
65
65
|
person.name # => "Rodrigo"
|
66
66
|
person.age # => 23
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.3
|
@@ -17,14 +17,19 @@ module PhpSerialization
|
|
17
17
|
when Array then
|
18
18
|
idx = -1
|
19
19
|
items = object.map { |item| "#{run(idx += 1)}#{run(item)}" }.join
|
20
|
-
"a:#{object.length}:{#{items}}
|
20
|
+
"a:#{object.length}:{#{items}}"
|
21
21
|
when Hash then
|
22
22
|
items = object.map { |key,value| "#{run(key)}#{run(value)}" }.join
|
23
|
-
"a:#{object.length}:{#{items}}
|
23
|
+
"a:#{object.length}:{#{items}}"
|
24
24
|
else
|
25
25
|
klass_name = object.class.name
|
26
|
+
|
27
|
+
if klass_name =~ /^Struct::/ && php_klass = object.instance_variable_get("@_php_class")
|
28
|
+
klass_name = php_klass
|
29
|
+
end
|
30
|
+
|
26
31
|
attributes = object.instance_variables.map { |var_name| "#{run(var_name.gsub(/^@/, ''))}#{run(object.instance_variable_get(var_name))}" }
|
27
|
-
"O:#{klass_name.length}:\"#{klass_name}\":#{object.instance_variables.length}:{#{attributes}}
|
32
|
+
"O:#{klass_name.length}:\"#{klass_name}\":#{object.instance_variables.length}:{#{attributes}}"
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -31,84 +31,83 @@ module_eval(<<'...end unserializer.y/module_eval...', 'unserializer.y', 69)
|
|
31
31
|
##### State transition tables begin ###
|
32
32
|
|
33
33
|
racc_action_table = [
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
5, 6, 19, 20, 9, 11, 13, 21, 1, 5,
|
35
|
+
6, 4, 22, 9, 11, 13, 23, 1, 5, 6,
|
36
|
+
4, 24, 9, 11, 13, 25, 1, 26, 46, 4,
|
37
|
+
5, 6, 27, 28, 9, 11, 13, 29, 1, 30,
|
38
|
+
52, 4, 18, 32, 33, 34, 35, 36, 37, 38,
|
39
|
+
39, 40, 41, 43, 45, 17, 49, 16, 31 ]
|
40
40
|
|
41
41
|
racc_action_check = [
|
42
|
-
0, 0,
|
43
|
-
48, 0,
|
44
|
-
48,
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
0, 0, 7, 8, 0, 0, 0, 9, 0, 48,
|
43
|
+
48, 0, 10, 48, 48, 48, 11, 48, 44, 44,
|
44
|
+
48, 12, 44, 44, 44, 13, 44, 14, 44, 44,
|
45
|
+
51, 51, 15, 16, 51, 51, 51, 17, 51, 18,
|
46
|
+
51, 51, 6, 21, 23, 25, 28, 29, 34, 35,
|
47
|
+
36, 37, 38, 41, 43, 4, 45, 1, 19 ]
|
48
48
|
|
49
49
|
racc_action_pointer = [
|
50
|
-
-3,
|
51
|
-
|
52
|
-
|
53
|
-
nil,
|
54
|
-
|
55
|
-
nil, nil ]
|
50
|
+
-3, 52, nil, nil, 50, nil, 37, 2, 1, 2,
|
51
|
+
10, 11, 19, 20, 25, 30, 27, 31, 33, 58,
|
52
|
+
nil, 37, nil, 38, nil, 39, nil, nil, 41, 42,
|
53
|
+
nil, nil, nil, nil, 43, 39, 38, 41, 47, nil,
|
54
|
+
nil, 47, nil, 49, 15, 44, nil, nil, 6, nil,
|
55
|
+
nil, 27, nil ]
|
56
56
|
|
57
57
|
racc_action_default = [
|
58
|
-
-
|
59
|
-
-
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
-
|
58
|
+
-19, -19, -6, -7, -19, -8, -19, -19, -19, -19,
|
59
|
+
-19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
|
60
|
+
-1, -19, -2, -19, -3, -19, -4, -5, -19, -19,
|
61
|
+
-9, 53, -10, -11, -19, -19, -19, -19, -19, -17,
|
62
|
+
-12, -19, -15, -19, -19, -19, -18, -14, -19, -15,
|
63
|
+
-16, -19, -13 ]
|
64
64
|
|
65
65
|
racc_goto_table = [
|
66
|
-
|
66
|
+
7, 44, 42, nil, nil, nil, nil, nil, 51, nil,
|
67
67
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
68
68
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
69
69
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
70
|
-
nil, nil, nil, nil, nil, nil, nil,
|
70
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 50 ]
|
71
71
|
|
72
72
|
racc_goto_check = [
|
73
|
-
|
73
|
+
1, 9, 11, nil, nil, nil, nil, nil, 9, nil,
|
74
74
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
75
75
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
76
76
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
77
|
-
nil, nil, nil, nil, nil, nil, nil,
|
77
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 1 ]
|
78
78
|
|
79
79
|
racc_goto_pointer = [
|
80
|
-
nil,
|
81
|
-
|
80
|
+
nil, 0, nil, nil, nil, nil, nil, nil, nil, -41,
|
81
|
+
nil, -37 ]
|
82
82
|
|
83
83
|
racc_goto_default = [
|
84
|
-
nil,
|
85
|
-
|
84
|
+
nil, 48, 8, 10, 12, 14, 15, 2, 3, nil,
|
85
|
+
47, nil ]
|
86
86
|
|
87
87
|
racc_reduce_table = [
|
88
88
|
0, 0, :racc_error,
|
89
89
|
2, 16, :_reduce_1,
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
1,
|
95
|
-
1,
|
90
|
+
2, 16, :_reduce_2,
|
91
|
+
2, 16, :_reduce_3,
|
92
|
+
2, 16, :_reduce_4,
|
93
|
+
2, 16, :_reduce_5,
|
94
|
+
1, 16, :_reduce_6,
|
95
|
+
1, 16, :_reduce_7,
|
96
96
|
1, 17, :_reduce_8,
|
97
|
-
|
97
|
+
3, 18, :_reduce_9,
|
98
98
|
3, 19, :_reduce_10,
|
99
99
|
3, 20, :_reduce_11,
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
8, 22, :_reduce_19 ]
|
100
|
+
5, 21, :_reduce_12,
|
101
|
+
11, 23, :_reduce_13,
|
102
|
+
2, 24, :_reduce_14,
|
103
|
+
0, 24, :_reduce_15,
|
104
|
+
2, 25, :_reduce_16,
|
105
|
+
0, 26, :_reduce_17,
|
106
|
+
8, 22, :_reduce_18 ]
|
108
107
|
|
109
|
-
racc_reduce_n =
|
108
|
+
racc_reduce_n = 19
|
110
109
|
|
111
|
-
racc_shift_n =
|
110
|
+
racc_shift_n = 53
|
112
111
|
|
113
112
|
racc_token_table = {
|
114
113
|
false => 0,
|
@@ -164,14 +163,13 @@ Racc_token_to_s_table = [
|
|
164
163
|
"\"}\"",
|
165
164
|
"\"a\"",
|
166
165
|
"$start",
|
167
|
-
"serialization",
|
168
166
|
"data",
|
169
167
|
"null",
|
170
168
|
"bool",
|
171
169
|
"integer",
|
172
170
|
"double",
|
173
|
-
"array",
|
174
171
|
"string",
|
172
|
+
"array",
|
175
173
|
"object",
|
176
174
|
"attribute_list",
|
177
175
|
"attribute",
|
@@ -190,141 +188,137 @@ module_eval(<<'.,.,', 'unserializer.y', 3)
|
|
190
188
|
end
|
191
189
|
.,.,
|
192
190
|
|
193
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
191
|
+
module_eval(<<'.,.,', 'unserializer.y', 4)
|
194
192
|
def _reduce_2(val, _values, result)
|
195
|
-
|
193
|
+
@object = val[0]
|
196
194
|
result
|
197
195
|
end
|
198
196
|
.,.,
|
199
197
|
|
200
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
198
|
+
module_eval(<<'.,.,', 'unserializer.y', 5)
|
201
199
|
def _reduce_3(val, _values, result)
|
202
|
-
|
200
|
+
@object = val[0]
|
203
201
|
result
|
204
202
|
end
|
205
203
|
.,.,
|
206
204
|
|
207
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
205
|
+
module_eval(<<'.,.,', 'unserializer.y', 6)
|
208
206
|
def _reduce_4(val, _values, result)
|
209
|
-
|
207
|
+
@object = val[0]
|
210
208
|
result
|
211
209
|
end
|
212
210
|
.,.,
|
213
211
|
|
214
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
212
|
+
module_eval(<<'.,.,', 'unserializer.y', 7)
|
215
213
|
def _reduce_5(val, _values, result)
|
216
|
-
|
214
|
+
@object = val[0]
|
217
215
|
result
|
218
216
|
end
|
219
217
|
.,.,
|
220
218
|
|
221
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
219
|
+
module_eval(<<'.,.,', 'unserializer.y', 8)
|
222
220
|
def _reduce_6(val, _values, result)
|
223
|
-
|
221
|
+
@object = val[0]
|
224
222
|
result
|
225
223
|
end
|
226
224
|
.,.,
|
227
225
|
|
228
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
226
|
+
module_eval(<<'.,.,', 'unserializer.y', 9)
|
229
227
|
def _reduce_7(val, _values, result)
|
230
|
-
|
228
|
+
@object = val[0]
|
231
229
|
result
|
232
230
|
end
|
233
231
|
.,.,
|
234
232
|
|
235
233
|
module_eval(<<'.,.,', 'unserializer.y', 12)
|
236
234
|
def _reduce_8(val, _values, result)
|
237
|
-
result =
|
235
|
+
result = nil
|
238
236
|
result
|
239
237
|
end
|
240
238
|
.,.,
|
241
239
|
|
242
240
|
module_eval(<<'.,.,', 'unserializer.y', 15)
|
243
241
|
def _reduce_9(val, _values, result)
|
244
|
-
result =
|
242
|
+
result = Integer(val[2]) > 0
|
245
243
|
result
|
246
244
|
end
|
247
245
|
.,.,
|
248
246
|
|
249
247
|
module_eval(<<'.,.,', 'unserializer.y', 18)
|
250
248
|
def _reduce_10(val, _values, result)
|
251
|
-
result = Integer(val[2])
|
249
|
+
result = Integer(val[2])
|
252
250
|
result
|
253
251
|
end
|
254
252
|
.,.,
|
255
253
|
|
256
254
|
module_eval(<<'.,.,', 'unserializer.y', 21)
|
257
255
|
def _reduce_11(val, _values, result)
|
258
|
-
result =
|
256
|
+
result = Float(val[2])
|
259
257
|
result
|
260
258
|
end
|
261
259
|
.,.,
|
262
260
|
|
263
261
|
module_eval(<<'.,.,', 'unserializer.y', 24)
|
264
262
|
def _reduce_12(val, _values, result)
|
265
|
-
result = Float(val[2])
|
266
|
-
result
|
267
|
-
end
|
268
|
-
.,.,
|
269
|
-
|
270
|
-
module_eval(<<'.,.,', 'unserializer.y', 27)
|
271
|
-
def _reduce_13(val, _values, result)
|
272
263
|
result = val[4]
|
273
264
|
result
|
274
265
|
end
|
275
266
|
.,.,
|
276
267
|
|
277
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
278
|
-
def
|
279
|
-
if
|
268
|
+
module_eval(<<'.,.,', 'unserializer.y', 29)
|
269
|
+
def _reduce_13(val, _values, result)
|
270
|
+
if eval("defined?(#{val[4]})")
|
280
271
|
result = Object.const_get(val[4]).new
|
281
272
|
|
282
273
|
val[9].each do |(attr_name, value)|
|
283
|
-
result.instance_variable_set("@#{attr_name}", value)
|
274
|
+
result.instance_variable_set("@#{attr_name.gsub(/(^\*)|\0/, '')}", value)
|
284
275
|
end
|
285
276
|
else
|
286
|
-
|
277
|
+
klass_name = val[4].gsub(/^Struct::/, '')
|
278
|
+
result = Struct.new(klass_name, *val[9].map { |(k,v)| k.gsub(/(^\*)|\0/, '').to_sym }).new(*val[9].map { |(k,v)| v })
|
279
|
+
result.instance_variable_set("@_php_class", klass_name)
|
287
280
|
end
|
288
281
|
|
289
282
|
result
|
290
283
|
end
|
291
284
|
.,.,
|
292
285
|
|
293
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
294
|
-
def
|
286
|
+
module_eval(<<'.,.,', 'unserializer.y', 43)
|
287
|
+
def _reduce_14(val, _values, result)
|
295
288
|
result = val[0] << val[1]
|
296
289
|
result
|
297
290
|
end
|
298
291
|
.,.,
|
299
292
|
|
300
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
301
|
-
def
|
293
|
+
module_eval(<<'.,.,', 'unserializer.y', 44)
|
294
|
+
def _reduce_15(val, _values, result)
|
302
295
|
result = []
|
303
296
|
result
|
304
297
|
end
|
305
298
|
.,.,
|
306
299
|
|
307
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
308
|
-
def
|
309
|
-
@numeric_array = false unless val[0].is_a?(Integer); result = [val[0], val[
|
300
|
+
module_eval(<<'.,.,', 'unserializer.y', 47)
|
301
|
+
def _reduce_16(val, _values, result)
|
302
|
+
@numeric_array = false unless val[0].is_a?(Integer); result = [val[0], val[1]]
|
310
303
|
result
|
311
304
|
end
|
312
305
|
.,.,
|
313
306
|
|
314
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
315
|
-
def
|
307
|
+
module_eval(<<'.,.,', 'unserializer.y', 50)
|
308
|
+
def _reduce_17(val, _values, result)
|
316
309
|
@numeric_array = true
|
317
310
|
result
|
318
311
|
end
|
319
312
|
.,.,
|
320
313
|
|
321
|
-
module_eval(<<'.,.,', 'unserializer.y',
|
322
|
-
def
|
314
|
+
module_eval(<<'.,.,', 'unserializer.y', 52)
|
315
|
+
def _reduce_18(val, _values, result)
|
323
316
|
if @numeric_array
|
324
317
|
result = []
|
325
318
|
val[6].each { |(i,v)| result[i] = v }
|
326
319
|
else
|
327
|
-
result =
|
320
|
+
result = {}
|
321
|
+
val[6].each { |(k, v)| result[k] = v}
|
328
322
|
end
|
329
323
|
|
330
324
|
result
|
@@ -1,16 +1,13 @@
|
|
1
1
|
class PhpSerialization::Unserializer
|
2
2
|
rule
|
3
3
|
|
4
|
-
|
5
|
-
;
|
6
|
-
|
7
|
-
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| array { result = val[0] }
|
12
|
-
| string { result = val[0] }
|
13
|
-
| object { result = val[0] }
|
4
|
+
data : null ';' { @object = val[0] }
|
5
|
+
| bool ';' { @object = val[0] }
|
6
|
+
| integer ';' { @object = val[0] }
|
7
|
+
| double ';' { @object = val[0] }
|
8
|
+
| string ';' { @object = val[0] }
|
9
|
+
| array { @object = val[0] }
|
10
|
+
| object { @object = val[0] }
|
14
11
|
;
|
15
12
|
|
16
13
|
null : 'N' { result = nil }
|
@@ -30,14 +27,16 @@ rule
|
|
30
27
|
|
31
28
|
object : 'O' ':' NUMBER ':' STRING ':' NUMBER ':' '{' attribute_list '}'
|
32
29
|
{
|
33
|
-
if
|
30
|
+
if eval("defined?(#{val[4]})")
|
34
31
|
result = Object.const_get(val[4]).new
|
35
32
|
|
36
33
|
val[9].each do |(attr_name, value)|
|
37
|
-
result.instance_variable_set("@#{attr_name}", value)
|
34
|
+
result.instance_variable_set("@#{attr_name.gsub(/(^\*)|\0/, '')}", value)
|
38
35
|
end
|
39
36
|
else
|
40
|
-
|
37
|
+
klass_name = val[4].gsub(/^Struct::/, '')
|
38
|
+
result = Struct.new(klass_name, *val[9].map { |(k,v)| k.gsub(/(^\*)|\0/, '').to_sym }).new(*val[9].map { |(k,v)| v })
|
39
|
+
result.instance_variable_set("@_php_class", klass_name)
|
41
40
|
end
|
42
41
|
}
|
43
42
|
;
|
@@ -46,7 +45,7 @@ rule
|
|
46
45
|
| { result = [] }
|
47
46
|
;
|
48
47
|
|
49
|
-
attribute : data
|
48
|
+
attribute : data data { @numeric_array = false unless val[0].is_a?(Integer); result = [val[0], val[1]] }
|
50
49
|
;
|
51
50
|
|
52
51
|
array : 'a' ':' NUMBER ':' '{' { @numeric_array = true } attribute_list '}'
|
@@ -55,7 +54,8 @@ rule
|
|
55
54
|
result = []
|
56
55
|
val[6].each { |(i,v)| result[i] = v }
|
57
56
|
else
|
58
|
-
result =
|
57
|
+
result = {}
|
58
|
+
val[6].each { |(k, v)| result[k] = v}
|
59
59
|
end
|
60
60
|
}
|
61
61
|
;
|
@@ -80,4 +80,4 @@ require 'php_serialization/tokenizer'
|
|
80
80
|
|
81
81
|
def next_token
|
82
82
|
@tokenizer.next_token
|
83
|
-
end
|
83
|
+
end
|
data/lib/php_serialization.rb
CHANGED
data/php-serialization.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{php-serialization}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rodrigo Kochenburger"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-18}
|
13
13
|
s.description = %q{Pure Ruby implementation of php's methods: serialize() and unserializer()}
|
14
14
|
s.email = %q{divoxx@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.homepage = %q{http://github.com/divoxx/ruby-php-serialization}
|
42
42
|
s.rdoc_options = ["--charset=UTF-8"]
|
43
43
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.
|
44
|
+
s.rubygems_version = %q{1.3.5}
|
45
45
|
s.summary = %q{PHP's serialization implementation for ruby}
|
46
46
|
s.test_files = [
|
47
47
|
"spec/serialization_spec.rb",
|
@@ -69,3 +69,4 @@ Gem::Specification.new do |s|
|
|
69
69
|
s.add_dependency(%q<racc>, [">= 0"])
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
data/spec/serialization_spec.rb
CHANGED
@@ -26,11 +26,11 @@ describe "Serialization" do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should unzerialize an array" do
|
29
|
-
PhpSerialization.dump([true, "foo"]).should == 'a:2:{i:0;b:1;i:1;s:3:"foo";}
|
29
|
+
PhpSerialization.dump([true, "foo"]).should == 'a:2:{i:0;b:1;i:1;s:3:"foo";}'
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should serialize a hash" do
|
33
|
-
PhpSerialization.dump("name" => "Rodrigo", "age" => 23).should == 'a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
33
|
+
PhpSerialization.dump("name" => "Rodrigo", "age" => 23).should == 'a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}'
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should serialize object with class existant" do
|
@@ -42,7 +42,7 @@ describe "Serialization" do
|
|
42
42
|
person.name = "Rodrigo"
|
43
43
|
person.age = 23
|
44
44
|
|
45
|
-
PhpSerialization.dump(person).should == 'O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
45
|
+
PhpSerialization.dump(person).should == 'O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}'
|
46
46
|
|
47
47
|
Object.send(:remove_const, :Person)
|
48
48
|
end
|
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/spec_helper"
|
|
2
2
|
|
3
3
|
describe "Session serialization" do
|
4
4
|
it "should store session correctly" do
|
5
|
-
PhpSessionSerialization.load("userId|i:123;store|s:3:\"foo\";someArr|a:2:{i:0;b:1;i:1;s:3:\"foo\";}
|
5
|
+
PhpSessionSerialization.load("userId|i:123;store|s:3:\"foo\";someArr|a:2:{i:0;b:1;i:1;s:3:\"foo\";}").should == {
|
6
6
|
"userId" => 123,
|
7
7
|
"store" => "foo",
|
8
8
|
"someArr" => [true, "foo"]
|
@@ -22,29 +22,28 @@ describe "Unserialization" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should unzerialize an array" do
|
25
|
-
PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";}
|
25
|
+
PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";}').should == [true, "foo"]
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should unserialize a hash" do
|
29
|
-
PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
29
|
+
PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}').should == {"name" => "Rodrigo", "age" => 23}
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should unserialize object with class existant" do
|
33
33
|
class Person
|
34
|
-
attr_accessor :name, :age
|
34
|
+
attr_accessor :name, :age, :gender
|
35
35
|
end
|
36
36
|
|
37
|
-
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
37
|
+
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
38
38
|
person.should be_instance_of(Person)
|
39
39
|
person.name.should == "Rodrigo"
|
40
40
|
person.age.should == 23
|
41
41
|
|
42
|
-
|
43
42
|
Object.send(:remove_const, :Person)
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should unserialize object without class as a struct" do
|
47
|
-
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}
|
46
|
+
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
48
47
|
person.should be_instance_of(Struct::Person)
|
49
48
|
person.name.should == "Rodrigo"
|
50
49
|
person.age.should == 23
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: php-serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-18 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
requirements: []
|
97
97
|
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.3.
|
99
|
+
rubygems_version: 1.3.5
|
100
100
|
signing_key:
|
101
101
|
specification_version: 3
|
102
102
|
summary: PHP's serialization implementation for ruby
|