php-serialize 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/php_serialize.rb +16 -23
  3. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9d3c32a1fe43d8186acdc93c67320994c69ae8d4
4
- data.tar.gz: 2fe820e15442213a58e8c084965583155cada091
2
+ SHA256:
3
+ metadata.gz: c1e2ab051accee52d022349801a297fbaa81c21ea025123291ebccb44cf3a28d
4
+ data.tar.gz: cceaed0eab97b037777dd37cb2c50f6e98e3d6b0c1a5f3f9f9f9cb9f392a7c5b
5
5
  SHA512:
6
- metadata.gz: 42a2a80a57cf7c4b57a80f65804172a95407a2d27f5ae9d7daca1a4224ffe3eee926efda691161917639d4959b1870f2e28db9c32add604419855954e1879578
7
- data.tar.gz: e656d868b8a3a1d87b8bcb5827021dd31b2fb729539388efab48e8f02938d4ee177046863b9950c7993b15c60a288387ded2b9b2acd9ac2fd3edb6a4ac691024
6
+ metadata.gz: ac582a23b37c737ecd86ffe611af1a5cb569a96462da61f77932dafd7450a7748dbd7155926008b6dda7ee36ca9ccdcc5844eb5f0ccb72670b65570a7bcac731
7
+ data.tar.gz: 337d048bc1c69c7ad52553d160d0c591ab9231a4ed6b0bd8f52ae6498e2e1f9d8817b6e3278f5a417e3217b3b548114515f7a059a9e9d7b94e23c86b83d6327c
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
 
3
5
  module PHP
@@ -27,7 +29,7 @@ module PHP
27
29
  # array will be assumed to be an associative array, and will be serialized
28
30
  # as a PHP associative array rather than a multidimensional array.
29
31
  def PHP.serialize(var, assoc = false) # {{{
30
- s = ''
32
+ s = String.new
31
33
  case var
32
34
  when Array
33
35
  s << "a:#{var.size}:{"
@@ -52,7 +54,7 @@ module PHP
52
54
 
53
55
  when Struct
54
56
  # encode as Object with same name
55
- s << "O:#{var.class.to_s.length}:\"#{var.class.to_s.downcase}\":#{var.members.length}:{"
57
+ s << "O:#{var.class.to_s.bytesize}:\"#{var.class.to_s.downcase}\":#{var.members.length}:{"
56
58
  var.members.each do |member|
57
59
  s << "#{PHP.serialize(member, assoc)}#{PHP.serialize(var[member], assoc)}"
58
60
  end
@@ -61,7 +63,7 @@ module PHP
61
63
  when String, Symbol
62
64
  s << "s:#{var.to_s.bytesize}:\"#{var.to_s}\";"
63
65
 
64
- when Fixnum # PHP doesn't have bignums
66
+ when Integer
65
67
  s << "i:#{var};"
66
68
 
67
69
  when Float
@@ -77,7 +79,7 @@ module PHP
77
79
  if var.respond_to?(:to_assoc)
78
80
  v = var.to_assoc
79
81
  # encode as Object with same name
80
- s << "O:#{var.class.to_s.length}:\"#{var.class.to_s.downcase}\":#{v.length}:{"
82
+ s << "O:#{var.class.to_s.bytesize}:\"#{var.class.to_s.downcase}\":#{v.length}:{"
81
83
  v.each do |k,v|
82
84
  s << "#{PHP.serialize(k.to_s, assoc)}#{PHP.serialize(v, assoc)}"
83
85
  end
@@ -95,11 +97,11 @@ module PHP
95
97
  #
96
98
  # string = PHP.serialize_session(mixed var[, bool assoc])
97
99
  def PHP.serialize_session(var, assoc = false) # {{{
98
- s = ''
100
+ s = String.new
99
101
  case var
100
102
  when Hash
101
103
  var.each do |key,value|
102
- if key.to_s =~ /\|/
104
+ if key.to_s.include?('|')
103
105
  raise IndexError, "Top level names may not contain pipes"
104
106
  end
105
107
  s << "#{key}|#{PHP.serialize(value, assoc)}"
@@ -168,7 +170,7 @@ module PHP
168
170
  ret[$1] = PHP.do_unserialize(string, classmap, assoc)
169
171
  end
170
172
 
171
- ret ? ret : PHP.do_unserialize(string, classmap, assoc)
173
+ ret || PHP.do_unserialize(string, classmap, assoc)
172
174
  end
173
175
 
174
176
  private
@@ -180,9 +182,9 @@ module PHP
180
182
  case type
181
183
  when 'a' # associative array, a:length:{[index][value]...}
182
184
  count = string.read_until('{').to_i
183
- val = vals = Array.new
185
+ val = Array.new
184
186
  count.times do |i|
185
- vals << [do_unserialize(string, classmap, assoc), do_unserialize(string, classmap, assoc)]
187
+ val << [do_unserialize(string, classmap, assoc), do_unserialize(string, classmap, assoc)]
186
188
  end
187
189
  string.read(1) # skip the ending }
188
190
 
@@ -190,7 +192,7 @@ module PHP
190
192
  # arrays have all numeric indexes, in order; otherwise we assume a hash
191
193
  array = true
192
194
  i = 0
193
- vals.each do |key,value|
195
+ val.each do |key,_|
194
196
  if key != i # wrong index -> assume hash
195
197
  array = false
196
198
  break
@@ -199,18 +201,9 @@ module PHP
199
201
  end
200
202
 
201
203
  if array
202
- vals.collect! do |key,value|
203
- value
204
- end
205
- else
206
- if assoc
207
- val = vals.map {|v| v }
208
- else
209
- val = Hash.new
210
- vals.each do |key,value|
211
- val[key] = value
212
- end
213
- end
204
+ val.map! {|_,value| value }
205
+ elsif !assoc
206
+ val = Hash[val]
214
207
  end
215
208
 
216
209
  when 'O' # object, O:length:"class":length:{[attribute][value]...}
@@ -264,7 +257,7 @@ module PHP
264
257
  val = nil
265
258
 
266
259
  when 'b' # bool, b:0 or 1
267
- val = (string.read(2)[0] == ?1 ? true : false)
260
+ val = string.read(2)[0] == '1'
268
261
 
269
262
  else
270
263
  raise TypeError, "Unable to unserialize type '#{type}'"
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Hurst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-29 00:00:00.000000000 Z
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -49,7 +49,7 @@ files:
49
49
  - lib/php-serialize.rb
50
50
  - lib/php_serialize.rb
51
51
  - test/php_serialize_test.rb
52
- homepage: http://www.aagh.net/projects/ruby-php-serialize
52
+ homepage: https://github.com/jqr/php-serialize
53
53
  licenses:
54
54
  - MIT
55
55
  metadata: {}
@@ -61,15 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: '0'
64
+ version: '2.4'
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.6.11
71
+ rubygems_version: 3.0.3
73
72
  signing_key:
74
73
  specification_version: 4
75
74
  summary: Ruby analogs to PHP's serialize() and unserialize() functions