Skip to content

Commit 06443f1

Browse files
committed
Add unit tests for unserialize()
1 parent 6d6c653 commit 06443f1

14 files changed

+63
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The use it the usual way :
2525
```javascript
2626
var PHPUnserialize = require('php-unserialize');
2727

28-
console.log(PHPUnserialize.unserialize('a:0:{}')); // []
28+
console.log(PHPUnserialize.unserialize('a:0:{}')); // {}
2929
```
3030

3131
### Browser
@@ -35,14 +35,19 @@ console.log(PHPUnserialize.unserialize('a:0:{}')); // []
3535
```html
3636
<script src="/path/to/php-unserialize.js"></script>
3737
<script>
38-
console.log(PHPUnserialize.unserialize('a:0:{}')); // []
38+
console.log(PHPUnserialize.unserialize('a:0:{}')); // {}
3939
</script>
4040
```
4141

4242
**Compatibility issues**
4343

4444
This library has been tested server-side only. For example it uses `[].reduce`, so it may not work on some browsers. Do not hesitate to make pull requests to fix it for you favorite browsers :)
4545

46+
### Notes
47+
48+
* Note that `array()` will be converted to `{}` and not `[]`. That can be discussed as `array()` in PHP has various significations. A choice had to be done, but it may change in the future (cf. next point).
49+
* A less obvious conversion is `array('a', 'b')` which will be converted to `{"0": "a", "1": "b"}`. Quite annoying, and it will be fixed if necessary (this means I won't work on this issue unless you really need it, but I agree this is not normal behavior).
50+
4651
Usage
4752
-----
4853

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
"url": "git://github.com/naholyr/js-php-unserialize.git"
99
},
1010
"main": "php-unserialize.js",
11+
"scripts": {
12+
"test": "./node_modules/.bin/_mocha -R list -u bdd"
13+
},
1114
"dependencies": {},
12-
"devDependencies": {},
15+
"devDependencies": {
16+
"chai": "~1.3.0",
17+
"mocha": "~1.7.0"
18+
},
1319
"optionalDependencies": {},
1420
"engines": {
1521
"node": "*"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:0:{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:1:{s:1:"i";i:42;}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
i:42;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:2:{i:0;s:3:"one";i:1;s:3:"two";}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lol invalid string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
O:8:"stdClass":0:{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_sf2_attributes|a:2:{s:3:"lol";s:4:"ROFL";s:8:"test-val";i:18;}_sf2_flashes|a:0:{}_sf2_meta|a:3:{s:1:"u";i:1352885566;s:1:"c";i:1352884188;s:1:"l";i:0;}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)