php-serialization 0.5.3 → 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 -5
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/{LICENSE → LICENSE.txt} +3 -1
- data/README.md +31 -0
- data/Rakefile +5 -67
- 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/serializer.rb +7 -7
- data/lib/php_serialization/tokenizer.rb +5 -5
- data/lib/php_serialization/unserializer.output +503 -0
- data/lib/php_serialization/unserializer.rb +67 -64
- data/lib/php_serialization/unserializer.y +39 -27
- 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 +100 -81
- data/.document +0 -5
- data/README.rdoc +0 -72
- data/VERSION +0 -1
- data/features/ruby_php_serialization.feature +0 -9
- data/features/step_definitions/ruby_php_serialization_steps.rb +0 -0
- data/features/support/env.rb +0 -4
- data/php-serialization.gemspec +0 -72
- data/spec/serialization_spec.rb +0 -49
- data/spec/session_serialization_spec.rb +0 -21
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -9
- data/spec/unserialization_spec.rb +0 -51
@@ -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
CHANGED
@@ -1,107 +1,126 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: php-serialization
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Rodrigo Kochenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2016-05-19 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'
|
17
20
|
type: :development
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
-
|
25
|
-
|
26
|
-
|
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'
|
27
34
|
type: :development
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
|
35
|
-
|
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
|
36
56
|
name: racc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
37
62
|
type: :runtime
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
41
66
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
47
72
|
executables: []
|
48
|
-
|
49
73
|
extensions: []
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
|
55
|
-
- .
|
56
|
-
- .
|
57
|
-
- LICENSE
|
58
|
-
- README.rdoc
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
59
81
|
- Rakefile
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
-
|
82
|
+
- bin/racc
|
83
|
+
- bin/racc2y
|
84
|
+
- bin/rake
|
85
|
+
- bin/rspec
|
86
|
+
- bin/y2racc
|
64
87
|
- lib/php_serialization.rb
|
65
88
|
- lib/php_serialization/serializer.rb
|
66
89
|
- lib/php_serialization/tokenizer.rb
|
90
|
+
- lib/php_serialization/unserializer.output
|
67
91
|
- lib/php_serialization/unserializer.rb
|
68
92
|
- lib/php_serialization/unserializer.y
|
69
|
-
-
|
70
|
-
-
|
71
|
-
- spec/session_serialization_spec.rb
|
72
|
-
- spec/
|
73
|
-
- spec/
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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: {}
|
79
102
|
post_install_message:
|
80
|
-
rdoc_options:
|
81
|
-
|
82
|
-
require_paths:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
83
105
|
- lib
|
84
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
86
108
|
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
89
|
-
|
90
|
-
|
91
|
-
requirements:
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
92
113
|
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version:
|
95
|
-
version:
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
96
116
|
requirements: []
|
97
|
-
|
98
117
|
rubyforge_project:
|
99
|
-
rubygems_version:
|
118
|
+
rubygems_version: 2.4.5
|
100
119
|
signing_key:
|
101
|
-
specification_version:
|
102
|
-
summary:
|
103
|
-
test_files:
|
104
|
-
- spec/
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
|
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
|
126
|
+
has_rdoc:
|
data/.document
DELETED
data/README.rdoc
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
= PhpSerialization
|
2
|
-
|
3
|
-
Ruby implementation of PHP's serialization. This is special useful for reading PHP session files.
|
4
|
-
|
5
|
-
== Serialization examples
|
6
|
-
|
7
|
-
Primitive values
|
8
|
-
|
9
|
-
PhpSerialization.dump(10) # => "i:10;"
|
10
|
-
PhpSerialization.dump("Name") # => "s:4:\"Name\";"
|
11
|
-
PhpSerialization.dump(true) # => "b:1;"
|
12
|
-
PhpSerialization.dump(nil) # => "N;"
|
13
|
-
|
14
|
-
Array
|
15
|
-
|
16
|
-
PhpSerialization.dump([true, "foo"]) # => "a:2:{i:0;b:1;i:1;s:3:\"foo\";}"
|
17
|
-
|
18
|
-
Hash
|
19
|
-
|
20
|
-
PhpSerialization.dump("name" => "Rodrigo", "age" => 23) # => "a:2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}"
|
21
|
-
|
22
|
-
Object
|
23
|
-
|
24
|
-
class Person
|
25
|
-
attr_accessor :name, :age
|
26
|
-
end
|
27
|
-
|
28
|
-
person = Person.new
|
29
|
-
person.name = "Rodrigo"
|
30
|
-
person.age = 23
|
31
|
-
|
32
|
-
PhpSerialization.dump(person) # => "O:6:\"Person\":2:{s:4:\"name\";s:7:\"Rodrigo\";s:3:\"age\";i:23;}"
|
33
|
-
|
34
|
-
== Unserialization examples
|
35
|
-
|
36
|
-
Primitive values
|
37
|
-
|
38
|
-
PhpSerialization.load('i:10;') # => 10
|
39
|
-
PhpSerialization.load('s:4:"Name";') # => "Name"
|
40
|
-
PhpSerialization.load('b:1;') # => true
|
41
|
-
PhpSerialization.load('N;') # => nil
|
42
|
-
|
43
|
-
Array
|
44
|
-
|
45
|
-
PhpSerialization.load('a:2:{i:0;b:1;i:1;s:3:"foo";}') # => [true, "foo"]
|
46
|
-
|
47
|
-
Hash
|
48
|
-
|
49
|
-
PhpSerialization.load('a:2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}') # => {"name" => "Rodrigo", "age" => 23}
|
50
|
-
|
51
|
-
Object
|
52
|
-
|
53
|
-
class Person
|
54
|
-
attr_accessor :name, :age
|
55
|
-
end
|
56
|
-
|
57
|
-
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
58
|
-
person.name # => "Rodrigo"
|
59
|
-
person.age # => 23
|
60
|
-
|
61
|
-
Object without class will map to a Struct
|
62
|
-
|
63
|
-
person = PhpSerialization.load('O:6:"Person":2:{s:4:"name";s:7:"Rodrigo";s:3:"age";i:23;}')
|
64
|
-
person.class # => Struct::Person
|
65
|
-
person.name # => "Rodrigo"
|
66
|
-
person.age # => 23
|
67
|
-
|
68
|
-
You can also call unserialize() or restore(), they are alias to the load().
|
69
|
-
|
70
|
-
== Copyright
|
71
|
-
|
72
|
-
Copyright (c) 2009 Rodrigo Kochenburger. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.5.3
|
File without changes
|
data/features/support/env.rb
DELETED
data/php-serialization.gemspec
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{php-serialization}
|
8
|
-
s.version = "0.5.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Rodrigo Kochenburger"]
|
12
|
-
s.date = %q{2009-12-18}
|
13
|
-
s.description = %q{Pure Ruby implementation of php's methods: serialize() and unserializer()}
|
14
|
-
s.email = %q{divoxx@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"features/ruby_php_serialization.feature",
|
27
|
-
"features/step_definitions/ruby_php_serialization_steps.rb",
|
28
|
-
"features/support/env.rb",
|
29
|
-
"lib/php_serialization.rb",
|
30
|
-
"lib/php_serialization/serializer.rb",
|
31
|
-
"lib/php_serialization/tokenizer.rb",
|
32
|
-
"lib/php_serialization/unserializer.rb",
|
33
|
-
"lib/php_serialization/unserializer.y",
|
34
|
-
"php-serialization.gemspec",
|
35
|
-
"spec/serialization_spec.rb",
|
36
|
-
"spec/session_serialization_spec.rb",
|
37
|
-
"spec/spec.opts",
|
38
|
-
"spec/spec_helper.rb",
|
39
|
-
"spec/unserialization_spec.rb"
|
40
|
-
]
|
41
|
-
s.homepage = %q{http://github.com/divoxx/ruby-php-serialization}
|
42
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
-
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.5}
|
45
|
-
s.summary = %q{PHP's serialization implementation for ruby}
|
46
|
-
s.test_files = [
|
47
|
-
"spec/serialization_spec.rb",
|
48
|
-
"spec/session_serialization_spec.rb",
|
49
|
-
"spec/spec_helper.rb",
|
50
|
-
"spec/unserialization_spec.rb"
|
51
|
-
]
|
52
|
-
|
53
|
-
if s.respond_to? :specification_version then
|
54
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
-
s.specification_version = 3
|
56
|
-
|
57
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
59
|
-
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
60
|
-
s.add_runtime_dependency(%q<racc>, [">= 0"])
|
61
|
-
else
|
62
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
63
|
-
s.add_dependency(%q<cucumber>, [">= 0"])
|
64
|
-
s.add_dependency(%q<racc>, [">= 0"])
|
65
|
-
end
|
66
|
-
else
|
67
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
68
|
-
s.add_dependency(%q<cucumber>, [">= 0"])
|
69
|
-
s.add_dependency(%q<racc>, [">= 0"])
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|