File tree 3 files changed +38
-12
lines changed
3 files changed +38
-12
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,14 @@ internals.stringify = function (obj, prefix) {
31
31
32
32
var values = [ ] ;
33
33
34
- for ( var key in obj ) {
35
- if ( obj . hasOwnProperty ( key ) ) {
36
- values = values . concat ( internals . stringify ( obj [ key ] , prefix + '[' + key + ']' ) ) ;
37
- }
34
+ if ( typeof obj === 'undefined' ) {
35
+ return values ;
36
+ }
37
+
38
+ var objKeys = Object . keys ( obj ) ;
39
+ for ( var i = 0 , il = objKeys . length ; i < il ; ++ i ) {
40
+ var key = objKeys [ i ] ;
41
+ values = values . concat ( internals . stringify ( obj [ key ] , prefix + '[' + key + ']' ) ) ;
38
42
}
39
43
40
44
return values ;
@@ -48,10 +52,10 @@ module.exports = function (obj, options) {
48
52
49
53
var keys = [ ] ;
50
54
51
- for ( var key in obj ) {
52
- if ( obj . hasOwnProperty ( key ) ) {
53
- keys = keys . concat ( internals . stringify ( obj [ key ] , key ) ) ;
54
- }
55
+ var objKeys = Object . keys ( obj ) ;
56
+ for ( var i = 0 , il = objKeys . length ; i < il ; ++ i ) {
57
+ var key = objKeys [ i ] ;
58
+ keys = keys . concat ( internals . stringify ( obj [ key ] , key ) ) ;
55
59
}
56
60
57
61
return keys . join ( delimiter ) ;
Original file line number Diff line number Diff line change @@ -130,10 +130,13 @@ exports.isRegExp = function (obj) {
130
130
131
131
exports . isBuffer = function ( obj ) {
132
132
133
- if ( typeof Buffer !== 'undefined' ) {
134
- return Buffer . isBuffer ( obj ) ;
135
- }
136
- else {
133
+ if ( obj === null ||
134
+ typeof obj === 'undefined' ) {
135
+
137
136
return false ;
138
137
}
138
+
139
+ return ! ! ( obj . constructor &&
140
+ obj . constructor . isBuffer &&
141
+ obj . constructor . isBuffer ( obj ) ) ;
139
142
} ;
Original file line number Diff line number Diff line change @@ -68,6 +68,25 @@ describe('stringify()', function () {
68
68
done ( ) ;
69
69
} ) ;
70
70
71
+ it ( 'stringifies an empty object' , function ( done ) {
72
+
73
+ var obj = Object . create ( null ) ;
74
+ obj . a = 'b' ;
75
+ expect ( Qs . stringify ( obj ) ) . to . equal ( 'a=b' ) ;
76
+ done ( ) ;
77
+ } ) ;
78
+
79
+ it ( 'stringifies an object with an empty object as a child' , function ( done ) {
80
+
81
+ var obj = {
82
+ a : Object . create ( null )
83
+ } ;
84
+
85
+ obj . a . b = 'c' ;
86
+ expect ( Qs . stringify ( obj ) ) . to . equal ( 'a%5Bb%5D=c' ) ;
87
+ done ( ) ;
88
+ } ) ;
89
+
71
90
it ( 'drops keys with a value of undefined' , function ( done ) {
72
91
73
92
expect ( Qs . stringify ( { a : undefined } ) ) . to . equal ( '' ) ;
You can’t perform that action at this time.
0 commit comments