Skip to content

Commit

Permalink
Merge pull request #5 from wild-r/master
Browse files Browse the repository at this point in the history
allow double quotes in string
  • Loading branch information
divoxx committed Feb 18, 2015
2 parents d6ad748 + 99f9bb1 commit 39cab77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/php_serialization/tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ def each
while !@string.empty?
token = case @string
when /\A-?[0-9]+(\.[0-9]+)?/m then yield([:NUMBER, $&])
when /\A"([^"]*)"/m then yield([:STRING, $1])
when /\A"((?:(?:"(?![;:]))*|(?:[^"]))*)"(?=[:;])/m then yield([:STRING, $1])
when /\A[^\s]/m then yield([$&, $&])
end

@string = $'
end

yield([false, '$'])
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/unserialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ class Person
person.name.should == "Rodrigo"
person.age.should == 23
end

it "should unserialize a string with double quotes" do
PhpSerialization.load('s:12:"new "Year"";').should == "new \"Year\""
end

it "should unserialize a string with double quotes in the middle" do
PhpSerialization.load("a:3:{i:0;s:4:\"test\";i:1;s:27:\"string with \"quotes\" inside\";s:2:\"in\";s:15:\"middle of array\";}").should == {0 => 'test',1 => 'string with "quotes" inside', 'in' => 'middle of array'}
end

end

0 comments on commit 39cab77

Please sign in to comment.