ruby-php-serialization 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/bin/racc +16 -0
- data/bin/racc2y +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/y2racc +16 -0
- data/lib/php_serialization.rb +48 -0
- data/lib/php_serialization/serializer.rb +36 -0
- data/lib/php_serialization/tokenizer.rb +21 -0
- data/lib/php_serialization/unserializer.output +503 -0
- data/lib/php_serialization/unserializer.rb +336 -0
- data/lib/php_serialization/unserializer.y +95 -0
- data/lib/php_serialization/version.rb +3 -0
- data/ruby-php-serialization.gemspec +26 -0
- data/spec/functional/session_serialization_spec.rb +23 -0
- data/spec/unit/serializer_spec.rb +49 -0
- data/spec/unit/unserializer_spec.rb +67 -0
- metadata +125 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require "php_serialization"
|
2
|
+
|
3
|
+
RSpec.describe "Session serialization" do
|
4
|
+
it "should store session correctly" do
|
5
|
+
data = PhpSessionSerialization.load("userId|i:123;store|s:3:\"foo\";someArr|a:2:{i:0;b:1;i:1;s:3:\"foo\";}")
|
6
|
+
expect(data).to eq(
|
7
|
+
"userId" => 123,
|
8
|
+
"store" => "foo",
|
9
|
+
"someArr" => [true, "foo"]
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should dump a hash as session" do
|
14
|
+
session_hash = {
|
15
|
+
"userId" => 123,
|
16
|
+
"store" => "foo",
|
17
|
+
"someArr" => [true, "foo"]
|
18
|
+
}
|
19
|
+
|
20
|
+
data = PhpSessionSerialization.load(PhpSessionSerialization.dump(session_hash))
|
21
|
+
expect(data).to eq(session_hash)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "php_serialization/serializer"
|
2
|
+
|
3
|
+
RSpec.describe PhpSerialization::Serializer do
|
4
|
+
it "should serialize a integer" do
|
5
|
+
expect(subject.run(10)).to eq("i:10;")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should serialize a string" do
|
9
|
+
expect(subject.run("Name")).to eq('s:4:"Name";')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should serialize a symbol string" do
|
13
|
+
expect(subject.run(:name)).to eq('s:4:"name";')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should serialize true" do
|
17
|
+
expect(subject.run(true)).to eq('b:1;')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should serialize false" do
|
21
|
+
expect(subject.run(false)).to eq('b:0;')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should serialize nil" do
|
25
|
+
expect(subject.run(nil)).to eq('N;')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should unzerialize an array" do
|
29
|
+
expect(subject.run([true, "foo"])).to eq('a:2:{i:0;b:1;i:1;s:3:"foo";}')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should serialize a hash" do
|
33
|
+
expect(subject.run("name" => "Rodrigo", "age" => 23)).to eq('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should serialize object with class existant" do
|
37
|
+
class Person
|
38
|
+
attr_accessor :name, :age
|
39
|
+
end
|
40
|
+
|
41
|
+
person = Person.new
|
42
|
+
person.name = "Rodrigo"
|
43
|
+
person.age = 23
|
44
|
+
|
45
|
+
expect(subject.run(person)).to eq("O:6:\"Person\":2:{s:3:\"age\";i:23;s:4:\"name\";s:7:\"Rodrigo\";}")
|
46
|
+
|
47
|
+
Object.send(:remove_const, :Person)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "php_serialization/unserializer"
|
2
|
+
|
3
|
+
RSpec.describe PhpSerialization::Unserializer do
|
4
|
+
it "should unserialize a integer" do
|
5
|
+
expect(subject.run("i:10;")).to eq 10
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should unserialize a string" do
|
9
|
+
expect(subject.run('s:4:"Name";')).to eq "Name"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should unserialize true" do
|
13
|
+
expect(subject.run('b:1;')).to eq true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should unserialize false" do
|
17
|
+
expect(subject.run('b:0;')).to eq false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should unserialize nil" do
|
21
|
+
expect(subject.run('N;')).to eq nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should unzerialize an array" do
|
25
|
+
expect(subject.run('a:2:{i:0;b:1;i:1;s:3:"foo";}')).to eq [true, "foo"]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should unserialize a hash" do
|
29
|
+
expect(subject.run('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')).to eq("name" => "Rodrigo", "age" => 23)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should unserialize object with class existant" do
|
33
|
+
class Person
|
34
|
+
attr_accessor :name, :age, :gender
|
35
|
+
end
|
36
|
+
|
37
|
+
person = subject.run('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
38
|
+
expect(person).to be_instance_of(Person)
|
39
|
+
expect(person.name).to eq "Rodrigo"
|
40
|
+
expect(person.age).to eq 23
|
41
|
+
|
42
|
+
Object.send(:remove_const, :Person)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should unserialize object without class as a struct" do
|
46
|
+
person = subject.run('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
47
|
+
expect(person).to be_instance_of(Struct::Person)
|
48
|
+
expect(person.name).to eq "Rodrigo"
|
49
|
+
expect(person.age).to eq 23
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should unserialize a string with double quotes" do
|
53
|
+
expect(subject.run('s:12:"new "Year"";')).to eq "new \"Year\""
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should unserialize a string with double quotes in the middle" do
|
57
|
+
expect(subject.run("a:3:{i:0;s:4:\"test\";i:1;s:27:\"string with \"quotes\" inside\";s:2:\"in\";s:15:\"middle of array\";}")).to eq(0 => 'test',1 => 'string with "quotes" inside', 'in' => 'middle of array')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should unserialize a tricky hash that pretends being an array" do
|
61
|
+
expect(subject.run('a:1:{i:2;i:3;}')).to eq(2 => 3)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should unserialize a multi-dimensional mixed array/hash" do
|
65
|
+
expect(subject.run('a:1:{i:0;a:2:{i:14;a:1:{i:0;i:2;}i:15;a:1:{i:0;i:3;}}}')).to eq [{14=>[2], 15=>[3]}]
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-php-serialization
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Kochenburger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: racc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: 'Pure Ruby implementation of php''s methods: serialize() and unserializer()'
|
70
|
+
email:
|
71
|
+
- divoxx@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/racc
|
83
|
+
- bin/racc2y
|
84
|
+
- bin/rake
|
85
|
+
- bin/rspec
|
86
|
+
- bin/y2racc
|
87
|
+
- lib/php_serialization.rb
|
88
|
+
- lib/php_serialization/serializer.rb
|
89
|
+
- lib/php_serialization/tokenizer.rb
|
90
|
+
- lib/php_serialization/unserializer.output
|
91
|
+
- lib/php_serialization/unserializer.rb
|
92
|
+
- lib/php_serialization/unserializer.y
|
93
|
+
- lib/php_serialization/version.rb
|
94
|
+
- ruby-php-serialization.gemspec
|
95
|
+
- spec/functional/session_serialization_spec.rb
|
96
|
+
- spec/unit/serializer_spec.rb
|
97
|
+
- spec/unit/unserializer_spec.rb
|
98
|
+
homepage: https://github.com/divoxx/ruby-php-serialization
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.8
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: 'Pure Ruby implementation of php''s methods: serialize() and unserializer()'
|
122
|
+
test_files:
|
123
|
+
- spec/functional/session_serialization_spec.rb
|
124
|
+
- spec/unit/serializer_spec.rb
|
125
|
+
- spec/unit/unserializer_spec.rb
|