Skip to content

Commit 3082715

Browse files
committed
fixup
The previous commit failed the test.
1 parent e6a0069 commit 3082715

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/php_serialize.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PhpObject < OpenStruct
2222
attr_accessor :_php_classname
2323

2424
def to_assoc
25-
each_pair
25+
each_pair.to_a
2626
end
2727
end
2828

@@ -90,8 +90,8 @@ def PHP.serialize(var, assoc = false) # {{{
9090
if var.respond_to?(:to_assoc)
9191
v = var.to_assoc
9292
# encode as Object with same name
93-
class_name = var&._php_classname || var.class.to_s
94-
s << "O:#{class_name.bytesize}:\"#{class_name.downcase}\":#{v.length}:{"
93+
class_name = var.respond_to?(:_php_classname) ? var._php_classname : var.class.to_s.downcase
94+
s << "O:#{class_name.bytesize}:\"#{class_name}\":#{v.length}:{"
9595
v.each do |k,v|
9696
s << "#{PHP.serialize(k.to_s, assoc)}#{PHP.serialize(v, assoc)}"
9797
end
@@ -221,7 +221,8 @@ def PHP.do_unserialize(string, classmap, assoc)
221221
when 'O' # object, O:length:"class":length:{[attribute][value]...}
222222
# class name (lowercase in PHP, grr)
223223
len = string.read_until(':').to_i + 3 # quotes, seperator
224-
klass = string.read(len)[1...-2].capitalize.intern # read it, kill useless quotes
224+
klass_in_php = string.read(len)[1...-2]
225+
klass = klass_in_php.capitalize.intern # read it, kill useless quotes
225226

226227
# read the attributes
227228
attrs = []
@@ -247,7 +248,7 @@ def PHP.do_unserialize(string, classmap, assoc)
247248
val = val.new
248249
rescue NameError # Nope; make a new PhpObject
249250
val = PhpObject.new.tap { |php_obj|
250-
php_obj._php_classname = klass.to_s
251+
php_obj._php_classname = klass_in_php.to_s
251252
}
252253
end
253254
end

test/php_serialize_test.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def self.test(ruby, php, opts = {})
7676
# PHP counts multibyte string, not string length
7777
def test_multibyte_string
7878
assert_equal "s:6:\"öäü\";", PHP.serialize("öäü")
79+
assert_equal PHP.unserialize("s:6:\"öäü\";"), "öäü"
7980
end
8081
# Verify assoc is passed down calls.
8182
# Slightly awkward because hashes don't guarantee order.
@@ -109,16 +110,16 @@ def test_sessions
109110
end
110111

111112
def test_creates_php_object_instance_if_class_undefined
112-
assert_nothing_raised do
113+
# assert_nothing_raised do
113114
phps = 'O:8:"stdClass":2:{s:3:"url";s:17:"/legacy/index.php";s:8:"dateTime";s:19:"2012-10-24 22:29:13";}'
114-
serialized = PHP.unserialize(phps)
115+
unserialized = PHP.unserialize(phps)
115116

116-
assert_kind_of PHP::PhpObject, serialized
117-
assert_equal "/legacy/index.php", serialized.url
117+
assert_kind_of PHP::PhpObject, unserialized
118+
assert_equal "/legacy/index.php", unserialized.url
118119

119-
reserialized = PHP.serialize(phps)
120+
reserialized = PHP.serialize(unserialized)
120121
assert_equal phps, reserialized
121-
end
122+
# end
122123
end
123124

124125
def test_same_classname_appears_twice

0 commit comments

Comments
 (0)