php-serialization 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -24,4 +24,25 @@ module PhpSerialization
24
24
  alias :restore :load
25
25
  alias :serialize :dump
26
26
  end
27
+ end
28
+
29
+ module PhpSessionSerialization
30
+ class << self
31
+ def load(str)
32
+ hash = {}
33
+
34
+ while str =~ /^([^|]+)\|(.*?;)(?=[^;|]+\||$)/
35
+ hash[$1] = PhpSerialization.load($2)
36
+ str = $'
37
+ end
38
+
39
+ hash
40
+ end
41
+
42
+ def dump(hash)
43
+ str = ""
44
+ hash.each { |key,value| str << "#{key}|#{PhpSerialization.dump(value)}" }
45
+ str
46
+ end
47
+ end
27
48
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{php-serialization}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rodrigo Kochenburger"]
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/php_serialization/unserializer.y",
34
34
  "php-serialization.gemspec",
35
35
  "spec/serialization_spec.rb",
36
+ "spec/session_serialization_spec.rb",
36
37
  "spec/spec.opts",
37
38
  "spec/spec_helper.rb",
38
39
  "spec/unserialization_spec.rb"
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
44
45
  s.summary = %q{PHP's serialization implementation for ruby}
45
46
  s.test_files = [
46
47
  "spec/serialization_spec.rb",
48
+ "spec/session_serialization_spec.rb",
47
49
  "spec/spec_helper.rb",
48
50
  "spec/unserialization_spec.rb"
49
51
  ]
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe "Session serialization" do
4
+ it "should store session correctly" do
5
+ PhpSessionSerialization.load("userId|i:123;store|s:3:\"foo\";someArr|a:2:{i:0;b:1;i:1;s:3:\"foo\";};").should == {
6
+ "userId" => 123,
7
+ "store" => "foo",
8
+ "someArr" => [true, "foo"]
9
+ }
10
+ end
11
+
12
+ it "should dump a hash as session" do
13
+ session_hash = {
14
+ "userId" => 123,
15
+ "store" => "foo",
16
+ "someArr" => [true, "foo"]
17
+ }
18
+
19
+ PhpSessionSerialization.load(PhpSessionSerialization.dump(session_hash)).should == session_hash
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: php-serialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Kochenburger
@@ -68,6 +68,7 @@ files:
68
68
  - lib/php_serialization/unserializer.y
69
69
  - php-serialization.gemspec
70
70
  - spec/serialization_spec.rb
71
+ - spec/session_serialization_spec.rb
71
72
  - spec/spec.opts
72
73
  - spec/spec_helper.rb
73
74
  - spec/unserialization_spec.rb
@@ -101,5 +102,6 @@ specification_version: 3
101
102
  summary: PHP's serialization implementation for ruby
102
103
  test_files:
103
104
  - spec/serialization_spec.rb
105
+ - spec/session_serialization_spec.rb
104
106
  - spec/spec_helper.rb
105
107
  - spec/unserialization_spec.rb