Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Let's always serialize obj attributes ordered lexicographically

  • Loading branch information...
commit 89d85fda63bf51a38e9b9ef43b4ac41db3c5c9e4 1 parent 278b6d2
@divoxx authored
View
2  lib/php_serialization/serializer.rb
@@ -28,7 +28,7 @@ def run(object)
klass_name = php_klass
end
- attributes = object.instance_variables.map { |var_name| "#{run(var_name.to_s.gsub(/^@/, ''))}#{run(object.instance_variable_get(var_name))}" }
+ attributes = object.instance_variables.sort.map { |var_name| "#{run(var_name.to_s.gsub(/^@/, ''))}#{run(object.instance_variable_get(var_name))}" }
"O:#{klass_name.length}:\"#{klass_name}\":#{object.instance_variables.length}:{#{attributes.join}}"
end
end
View
2  spec/unit/serializer_spec.rb
@@ -42,7 +42,7 @@ class Person
person.name = "Rodrigo"
person.age = 23
- expect(subject.run(person)).to eq('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
+ expect(subject.run(person)).to eq("O:6:\"Person\":2:{s:3:\"age\";i:23;s:4:\"name\";s:7:\"Rodrigo\";}")
Object.send(:remove_const, :Person)
end
Please sign in to comment.
Something went wrong with that request. Please try again.