@@ -118,7 +118,7 @@ test('parse()', function (t) {
118
118
st . end ( ) ;
119
119
} ) ;
120
120
121
- t . test ( 'should decode dot in key of object, and allow enabling dot notation when decodeDotInKeys is set to true and allowDots is undefined' , function ( st ) {
121
+ t . test ( 'decodes dot in key of object, and allow enabling dot notation when decodeDotInKeys is set to true and allowDots is undefined' , function ( st ) {
122
122
st . deepEqual (
123
123
qs . parse (
124
124
'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe' ,
@@ -131,7 +131,7 @@ test('parse()', function (t) {
131
131
st . end ( ) ;
132
132
} ) ;
133
133
134
- t . test ( 'should throw when decodeDotInKeys is not of type boolean' , function ( st ) {
134
+ t . test ( 'throws when decodeDotInKeys is not of type boolean' , function ( st ) {
135
135
st [ 'throws' ] (
136
136
function ( ) { qs . parse ( 'foo[]&bar=baz' , { decodeDotInKeys : 'foobar' } ) ; } ,
137
137
TypeError
@@ -161,7 +161,7 @@ test('parse()', function (t) {
161
161
st . end ( ) ;
162
162
} ) ;
163
163
164
- t . test ( 'should throw when allowEmptyArrays is not of type boolean' , function ( st ) {
164
+ t . test ( 'throws when allowEmptyArrays is not of type boolean' , function ( st ) {
165
165
st [ 'throws' ] (
166
166
function ( ) { qs . parse ( 'foo[]&bar=baz' , { allowEmptyArrays : 'foobar' } ) ; } ,
167
167
TypeError
@@ -444,7 +444,7 @@ test('parse()', function (t) {
444
444
st . end ( ) ;
445
445
} ) ;
446
446
447
- t . test ( 'should not throw when a native prototype has an enumerable property' , function ( st ) {
447
+ t . test ( 'does not throw when a native prototype has an enumerable property' , function ( st ) {
448
448
st . intercept ( Object . prototype , 'crash' , { value : '' } ) ;
449
449
st . intercept ( Array . prototype , 'crash' , { value : '' } ) ;
450
450
@@ -965,7 +965,7 @@ test('parse()', function (t) {
965
965
st . end ( ) ;
966
966
} ) ;
967
967
968
- t . test ( 'should ignore an utf8 sentinel with an unknown value' , function ( st ) {
968
+ t . test ( 'ignores an utf8 sentinel with an unknown value' , function ( st ) {
969
969
st . deepEqual ( qs . parse ( 'utf8=foo&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8 , { charsetSentinel : true , charset : 'utf-8' } ) , { ø : 'ø' } ) ;
970
970
st . end ( ) ;
971
971
} ) ;
@@ -1035,6 +1035,95 @@ test('parse()', function (t) {
1035
1035
st . end ( ) ;
1036
1036
} ) ;
1037
1037
1038
+ t . test ( 'parameter limit tests' , function ( st ) {
1039
+ st . test ( 'does not throw error when within parameter limit' , function ( sst ) {
1040
+ var result = qs . parse ( 'a=1&b=2&c=3' , { parameterLimit : 5 , throwOnLimitExceeded : true } ) ;
1041
+ sst . deepEqual ( result , { a : '1' , b : '2' , c : '3' } , 'parses without errors' ) ;
1042
+ sst . end ( ) ;
1043
+ } ) ;
1044
+
1045
+ st . test ( 'throws error when throwOnLimitExceeded is present but not boolean' , function ( sst ) {
1046
+ sst [ 'throws' ] (
1047
+ function ( ) {
1048
+ qs . parse ( 'a=1&b=2&c=3&d=4&e=5&f=6' , { parameterLimit : 3 , throwOnLimitExceeded : 'true' } ) ;
1049
+ } ,
1050
+ new TypeError ( '`throwOnLimitExceeded` option must be a boolean' ) ,
1051
+ 'throws error when throwOnLimitExceeded is present and not boolean'
1052
+ ) ;
1053
+ sst . end ( ) ;
1054
+ } ) ;
1055
+
1056
+ st . test ( 'throws error when parameter limit exceeded' , function ( sst ) {
1057
+ sst [ 'throws' ] (
1058
+ function ( ) {
1059
+ qs . parse ( 'a=1&b=2&c=3&d=4&e=5&f=6' , { parameterLimit : 3 , throwOnLimitExceeded : true } ) ;
1060
+ } ,
1061
+ new RangeError ( 'Parameter limit exceeded. Only 3 parameters allowed.' ) ,
1062
+ 'throws error when parameter limit is exceeded'
1063
+ ) ;
1064
+ sst . end ( ) ;
1065
+ } ) ;
1066
+
1067
+ st . test ( 'silently truncates when throwOnLimitExceeded is not given' , function ( sst ) {
1068
+ var result = qs . parse ( 'a=1&b=2&c=3&d=4&e=5' , { parameterLimit : 3 } ) ;
1069
+ sst . deepEqual ( result , { a : '1' , b : '2' , c : '3' } , 'parses and truncates silently' ) ;
1070
+ sst . end ( ) ;
1071
+ } ) ;
1072
+
1073
+ st . test ( 'silently truncates when parameter limit exceeded without error' , function ( sst ) {
1074
+ var result = qs . parse ( 'a=1&b=2&c=3&d=4&e=5' , { parameterLimit : 3 , throwOnLimitExceeded : false } ) ;
1075
+ sst . deepEqual ( result , { a : '1' , b : '2' , c : '3' } , 'parses and truncates silently' ) ;
1076
+ sst . end ( ) ;
1077
+ } ) ;
1078
+
1079
+ st . test ( 'allows unlimited parameters when parameterLimit set to Infinity' , function ( sst ) {
1080
+ var result = qs . parse ( 'a=1&b=2&c=3&d=4&e=5&f=6' , { parameterLimit : Infinity } ) ;
1081
+ sst . deepEqual ( result , { a : '1' , b : '2' , c : '3' , d : '4' , e : '5' , f : '6' } , 'parses all parameters without truncation' ) ;
1082
+ sst . end ( ) ;
1083
+ } ) ;
1084
+
1085
+ st . end ( ) ;
1086
+ } ) ;
1087
+
1088
+ t . test ( 'array limit tests' , function ( st ) {
1089
+ st . test ( 'does not throw error when array is within limit' , function ( sst ) {
1090
+ var result = qs . parse ( 'a[]=1&a[]=2&a[]=3' , { arrayLimit : 5 , throwOnLimitExceeded : true } ) ;
1091
+ sst . deepEqual ( result , { a : [ '1' , '2' , '3' ] } , 'parses array without errors' ) ;
1092
+ sst . end ( ) ;
1093
+ } ) ;
1094
+
1095
+ st . test ( 'throws error when throwOnLimitExceeded is present but not boolean for array limit' , function ( sst ) {
1096
+ sst [ 'throws' ] (
1097
+ function ( ) {
1098
+ qs . parse ( 'a[]=1&a[]=2&a[]=3&a[]=4' , { arrayLimit : 3 , throwOnLimitExceeded : 'true' } ) ;
1099
+ } ,
1100
+ new TypeError ( '`throwOnLimitExceeded` option must be a boolean' ) ,
1101
+ 'throws error when throwOnLimitExceeded is present and not boolean for array limit'
1102
+ ) ;
1103
+ sst . end ( ) ;
1104
+ } ) ;
1105
+
1106
+ st . test ( 'throws error when array limit exceeded' , function ( sst ) {
1107
+ sst [ 'throws' ] (
1108
+ function ( ) {
1109
+ qs . parse ( 'a[]=1&a[]=2&a[]=3&a[]=4' , { arrayLimit : 3 , throwOnLimitExceeded : true } ) ;
1110
+ } ,
1111
+ new RangeError ( 'Array limit exceeded. Only 3 elements allowed in an array.' ) ,
1112
+ 'throws error when array limit is exceeded'
1113
+ ) ;
1114
+ sst . end ( ) ;
1115
+ } ) ;
1116
+
1117
+ st . test ( 'converts array to object if length is greater than limit' , function ( sst ) {
1118
+ var result = qs . parse ( 'a[1]=1&a[2]=2&a[3]=3&a[4]=4&a[5]=5&a[6]=6' , { arrayLimit : 5 } ) ;
1119
+
1120
+ sst . deepEqual ( result , { a : { 1 : '1' , 2 : '2' , 3 : '3' , 4 : '4' , 5 : '5' , 6 : '6' } } , 'parses into object if array length is greater than limit' ) ;
1121
+ sst . end ( ) ;
1122
+ } ) ;
1123
+
1124
+ st . end ( ) ;
1125
+ } ) ;
1126
+
1038
1127
t . end ( ) ;
1039
1128
} ) ;
1040
1129
@@ -1093,7 +1182,7 @@ test('qs strictDepth option - throw cases', function (t) {
1093
1182
qs . parse ( 'a[b][c][d][e][f][g][h][i]=j' , { depth : 1 , strictDepth : true } ) ;
1094
1183
} ,
1095
1184
RangeError ,
1096
- 'Should throw RangeError'
1185
+ 'throws RangeError'
1097
1186
) ;
1098
1187
st . end ( ) ;
1099
1188
} ) ;
@@ -1104,7 +1193,7 @@ test('qs strictDepth option - throw cases', function (t) {
1104
1193
qs . parse ( 'a[0][1][2][3][4]=b' , { depth : 3 , strictDepth : true } ) ;
1105
1194
} ,
1106
1195
RangeError ,
1107
- 'Should throw RangeError'
1196
+ 'throws RangeError'
1108
1197
) ;
1109
1198
st . end ( ) ;
1110
1199
} ) ;
@@ -1115,7 +1204,7 @@ test('qs strictDepth option - throw cases', function (t) {
1115
1204
qs . parse ( 'a[b][c][0][d][e]=f' , { depth : 3 , strictDepth : true } ) ;
1116
1205
} ,
1117
1206
RangeError ,
1118
- 'Should throw RangeError'
1207
+ 'throws RangeError'
1119
1208
) ;
1120
1209
st . end ( ) ;
1121
1210
} ) ;
@@ -1126,7 +1215,7 @@ test('qs strictDepth option - throw cases', function (t) {
1126
1215
qs . parse ( 'a[b][c][d][e]=true&a[b][c][d][f]=42' , { depth : 3 , strictDepth : true } ) ;
1127
1216
} ,
1128
1217
RangeError ,
1129
- 'Should throw RangeError'
1218
+ 'throws RangeError'
1130
1219
) ;
1131
1220
st . end ( ) ;
1132
1221
} ) ;
@@ -1140,7 +1229,7 @@ test('qs strictDepth option - non-throw cases', function (t) {
1140
1229
qs . parse ( 'a[b][c][d][e]=true&a[b][c][d][f]=42' , { depth : 0 , strictDepth : true } ) ;
1141
1230
} ,
1142
1231
RangeError ,
1143
- 'Should not throw RangeError'
1232
+ 'does not throw RangeError'
1144
1233
) ;
1145
1234
st . end ( ) ;
1146
1235
} ) ;
@@ -1149,7 +1238,7 @@ test('qs strictDepth option - non-throw cases', function (t) {
1149
1238
st . doesNotThrow (
1150
1239
function ( ) {
1151
1240
var result = qs . parse ( 'a[b]=c' , { depth : 1 , strictDepth : true } ) ;
1152
- st . deepEqual ( result , { a : { b : 'c' } } , 'Should parse correctly' ) ;
1241
+ st . deepEqual ( result , { a : { b : 'c' } } , 'parses correctly' ) ;
1153
1242
}
1154
1243
) ;
1155
1244
st . end ( ) ;
@@ -1159,7 +1248,7 @@ test('qs strictDepth option - non-throw cases', function (t) {
1159
1248
st . doesNotThrow (
1160
1249
function ( ) {
1161
1250
var result = qs . parse ( 'a[b][c][d][e][f][g][h][i]=j' , { depth : 1 } ) ;
1162
- st . deepEqual ( result , { a : { b : { '[c][d][e][f][g][h][i]' : 'j' } } } , 'Should parse with depth limit' ) ;
1251
+ st . deepEqual ( result , { a : { b : { '[c][d][e][f][g][h][i]' : 'j' } } } , 'parses with depth limit' ) ;
1163
1252
}
1164
1253
) ;
1165
1254
st . end ( ) ;
@@ -1169,7 +1258,7 @@ test('qs strictDepth option - non-throw cases', function (t) {
1169
1258
st . doesNotThrow (
1170
1259
function ( ) {
1171
1260
var result = qs . parse ( 'a[b]=c' , { depth : 1 } ) ;
1172
- st . deepEqual ( result , { a : { b : 'c' } } , 'Should parse correctly' ) ;
1261
+ st . deepEqual ( result , { a : { b : 'c' } } , 'parses correctly' ) ;
1173
1262
}
1174
1263
) ;
1175
1264
st . end ( ) ;
@@ -1179,7 +1268,7 @@ test('qs strictDepth option - non-throw cases', function (t) {
1179
1268
st . doesNotThrow (
1180
1269
function ( ) {
1181
1270
var result = qs . parse ( 'a[b][c]=d' , { depth : 2 , strictDepth : true } ) ;
1182
- st . deepEqual ( result , { a : { b : { c : 'd' } } } , 'Should parse correctly' ) ;
1271
+ st . deepEqual ( result , { a : { b : { c : 'd' } } } , 'parses correctly' ) ;
1183
1272
}
1184
1273
) ;
1185
1274
st . end ( ) ;
0 commit comments