k-php-serialize 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/php_serialize.rb +15 -6
  3. data/test.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ca2fe3387bf53ef734923627612458e40617b53
4
- data.tar.gz: 641a388382641c7ecafa503366f8df96632ef99a
3
+ metadata.gz: 09dd982fb92ae4337a82442855f5b54c94c6fbeb
4
+ data.tar.gz: 06d11823f6271c88036f71f408c82f5ef2af48fa
5
5
  SHA512:
6
- metadata.gz: b1d1089a746f1b44b17d9ad1610efdb9baa629c93832fbf591354c3b9d0da2d185c24fd0e2463acf2721545eefcb9b6dbe1e15b43f00d1c993848af1e0fc9d44
7
- data.tar.gz: b9a5a79f1e2cf93e9eb36977971acebad374e51903a026efdb3b26f4d8322f003bf1add2f59105e87478c274f43b04966cd1dc6350d03b5f074679184cc2e8fc
6
+ metadata.gz: d0a0c45b0e12441ce2fc65e1a03e3138f4a351b3d6785748f11a30dc06afa8c46d518dbac781a095be0e23f5647bef7c1f6110f3016fb16406c542046fa16b42
7
+ data.tar.gz: ac0b7a07f168a32d6d61e66c6398eca3cab4715bd104bbc86e429cacbe75090291fc3d17946a4c5d8cefb5374ed6ec32ea417ed72d1ca4a7d2a52ba415d9ad7d
@@ -199,8 +199,8 @@ module PHP
199
199
  classmap ||= {}
200
200
 
201
201
  ret = nil
202
- original_encoding = string.encoding
203
- string = StringIOReader.new(string.force_encoding('BINARY'))
202
+ original_encoding = string.encoding if string.respond_to?(:encoding)
203
+ string = StringIOReader.new(string.respond_to?(:force_encoding) ? string.force_encoding('BINARY') : string)
204
204
  while string.string[string.pos, 32] =~ /^(\w+)\|/ # session_name|serialized_data
205
205
  ret ||= {}
206
206
  string.pos += $&.size
@@ -238,7 +238,11 @@ private
238
238
 
239
239
  if array
240
240
  vals.collect! do |key,value|
241
- value.kind_of?(String) ? value.force_encoding(original_encoding) : value
241
+ if value.respond_to? :force_encoding
242
+ value.kind_of?(String) ? value.force_encoding(original_encoding) : value
243
+ else
244
+ value
245
+ end
242
246
  end
243
247
  else
244
248
  if assoc
@@ -246,8 +250,12 @@ private
246
250
  else
247
251
  val = Hash.new
248
252
  vals.each do |key,value|
249
- key = key.force_encoding(original_encoding) if key.kind_of?(String)
250
- value = value.force_encoding(original_encoding) if value.kind_of?(String)
253
+
254
+ if value.respond_to? :force_encoding
255
+ key = key.force_encoding(original_encoding) if key.kind_of?(String)
256
+ value = value.force_encoding(original_encoding) if value.kind_of?(String)
257
+ end
258
+
251
259
  val[key] = value
252
260
  end
253
261
  end
@@ -292,7 +300,8 @@ private
292
300
 
293
301
  when 's' # string, s:length:"data";
294
302
  len = string.read_until(':').to_i + 3 # quotes, separator
295
- val = string.read(len)[1...-2].force_encoding(original_encoding) # read it, kill useless quotes
303
+ val = string.read(len)[1...-2] # read it, kill useless quotes
304
+ val = val.force_encoding(original_encoding) if val.respond_to?(:force_encoding)
296
305
 
297
306
  when 'i' # integer, i:123
298
307
  val = string.read_until(';').to_i
data/test.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'test/unit'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k-php-serialize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keitaroh Kobayashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-27 00:00:00.000000000 Z
11
+ date: 2013-06-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "\tThis module provides two methods: PHP.serialize() and PHP.unserialize(),
14
14
  both\n\tof which should be compatible with the similarly named functions in PHP.\n\n\tIt