Skip to content

Commit

Permalink
Merge pull request #422 from tcandens/bug/php-unserialize
Browse files Browse the repository at this point in the history
Bug fix for PHP unserialize
  • Loading branch information
kukawski committed Sep 21, 2020
2 parents d6b766a + 3b1a785 commit 916f5b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/php/var/unserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = function unserialize (data) {
// returns 4: false
// example 5: unserialize('O:8:"stdClass":1:{s:3:"foo";b:1;}')
// returns 5: { foo: true }
// example 6: unserialize('a:2:{i:0;N;i:1;s:0:"";')
// returns 6: [null, ""]

var utf8Overhead = function (str) {
var s = str.length
Expand Down Expand Up @@ -144,6 +146,7 @@ module.exports = function unserialize (data) {
readdata = readData[1]
dataoffset += chrs + 1
break
case 'N':
case 'n':
readdata = null
break
Expand Down
6 changes: 6 additions & 0 deletions test/languages/php/var/test-unserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ describe('src/php/var/unserialize.js (tested in test/languages/php/var/test-unse
expect(result).to.deep.equal(expected)
done()
})
it('should pass example 6', function (done) {
var expected = [null, ""]
var result = unserialize('a:2:{i:0;N;i:1;s:0:"";')
expect(result).to.deep.equal(expected)
done()
})
})

0 comments on commit 916f5b4

Please sign in to comment.