FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node-querystring/test/stringify.js at master · hotcoffee/node-querystring · GitHub
hotcoffee
/
node-querystring
Public
forked from
tj/node-querystring
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node-querystring
/
test
/
stringify.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
240 lines (198 loc) · 7.77 KB
Breadcrumbs
node-querystring
/
test
/
stringify.js
Copy path
File metadata and controls
240 lines (198 loc) · 7.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
if
(
require
.
register
)
{
var
qs
=
require
(
'querystring'
)
;
}
else
{
var
qs
=
require
(
'../'
)
,
expect
=
require
(
'expect.js'
)
;
}
describe
(
'qs.stringify'
,
function
(
)
{
describe
(
'basic'
,
function
(
)
{
it
(
'should stringify a basic parameter'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
'foo'
:
'bar'
}
)
)
.
to
.
eql
(
'foo=bar'
)
;
}
)
;
it
(
'should stringify a pair of string parameters delimited by &'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
'foo'
:
'bar'
,
'bar'
:
'baz'
}
)
)
.
to
.
eql
(
'foo=bar&bar=baz'
)
;
}
)
;
it
(
'should stringify and excaped char'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
'foo'
:
'\"bar\"'
}
)
)
.
to
.
eql
(
'foo=%22bar%22'
)
;
}
)
;
it
(
'should stringify to empty string if a value is missing'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
foo
:
''
}
)
)
.
to
.
eql
(
'foo='
)
;
}
)
;
it
(
'should stringify numeric values to strings'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
'foo'
:
'1'
,
'bar'
:
'2'
}
)
)
.
to
.
eql
(
'foo=1&bar=2'
)
;
}
)
;
it
(
'should stringify that weird field'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
'my weird field'
:
"q1!2\"'w$5&7/z8)?"
}
)
)
.
to
.
eql
(
'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F'
)
;
}
)
;
it
(
'should strigify a key name=name'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
'foo=baz'
:
'bar'
}
)
)
.
to
.
eql
(
'foo%3Dbaz=bar'
)
;
}
)
;
it
(
'should stringify a object with 2 properties'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
foo
:
'bar'
,
bar
:
'baz'
}
)
)
.
to
.
eql
(
'foo=bar&bar=baz'
)
;
}
)
;
it
(
'should strigify two empty values to not undefined'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
foo
:
'bar'
,
baz
:
''
,
raz
:
''
}
)
)
.
to
.
eql
(
'foo=bar&baz=&raz='
)
;
}
)
;
}
)
;
describe
(
'escaping'
,
function
(
)
{
it
(
'should work with escaping html entities in the value'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
foo
:
'foo bar'
}
)
)
.
to
.
eql
(
'foo=foo%20bar'
)
;
}
)
;
it
(
'should work with different forms of escaping html entities'
,
function
(
)
{
expect
(
qs
.
stringify
(
{
cht
:
'p3'
,
chd
:
't:60,40'
,
chs
:
'250x100'
,
chl
:
'Hello|World'
}
)
)
.
to
.
eql
(
'cht=p3&chd=t%3A60%2C40&chs=250x100&chl=Hello%7CWorld'
)
;
}
)
;
}
)
;
describe
(
'nested'
,
function
(
)
{
it
(
'should work with a simple array with one value'
,
function
(
)
{
var
str
=
'foo[0]=bar'
;
var
obj
=
{
'foo'
:
[
'bar'
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a simple array with two values'
,
function
(
)
{
var
str
=
'foo[0]=bar&foo[1]=quux'
;
var
obj
=
{
'foo'
:
[
'bar'
,
'quux'
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a simple array with two numeric values'
,
function
(
)
{
var
str
=
'foo[0]=0&foo[1]=1'
;
var
obj
=
{
'foo'
:
[
'0'
,
'1'
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a array and a object'
,
function
(
)
{
var
str
=
'foo=bar&baz[0]=1&baz[1]=2&baz[2]=3'
;
var
obj
=
{
'foo'
:
'bar'
,
'baz'
:
[
'1'
,
'2'
,
'3'
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a array containing string values and a array containing numeric values'
,
function
(
)
{
var
str
=
'foo[0]=bar&baz[0]=1&baz[1]=2&baz[2]=3'
;
var
obj
=
{
'foo'
:
[
'bar'
]
,
'baz'
:
[
'1'
,
'2'
,
'3'
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a array containing string values and a array containing numeric values'
,
function
(
)
{
var
str
=
'foo[0]=bar&baz[0]=1&baz[1]=2&baz[2]=3'
;
var
obj
=
{
'foo'
:
[
'bar'
]
,
'baz'
:
[
'1'
,
'2'
,
'3'
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a double nested array with string keys and a third level with a numeric key'
,
function
(
)
{
var
str
=
'x[y][z][0]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
{
'z'
:
[
'1'
]
}
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a nested array in string with string keys and a numeric value of 1'
,
function
(
)
{
var
str
=
'x[y][z]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
{
'z'
:
'1'
}
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with a nested array in string with string keys and a numeric value of 2'
,
function
(
)
{
var
str
=
'x[y][z]=2'
;
var
obj
=
{
'x'
:
{
'y'
:
{
'z'
:
'2'
}
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with array in double nesting'
,
function
(
)
{
var
str
=
'x[y][z][0]=1&x[y][z][1]=2'
;
var
obj
=
{
'x'
:
{
'y'
:
{
'z'
:
[
'1'
,
'2'
]
}
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with object, array, object nesting'
,
function
(
)
{
var
str
=
'x[y][0][z]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
'1'
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with object, array, object, array nesting'
,
function
(
)
{
var
str
=
'x[y][0][z][0]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
[
'1'
]
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with object, array, object, array nesting'
,
function
(
)
{
var
str
=
'x[y][0][z][0]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
[
'1'
]
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work with object, array, object, array nesting'
,
function
(
)
{
var
str
=
'x[y][0][z][0]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
[
'1'
]
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work for 2 objects nested with an array'
,
function
(
)
{
var
str
=
'x[y][0][z]=1&x[y][0][w]=2'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
'1'
,
'w'
:
'2'
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work for object, array, object nesting'
,
function
(
)
{
var
str
=
'x[y][0][v][w]=1'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'v'
:
{
'w'
:
'1'
}
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work for --'
,
function
(
)
{
var
str
=
'x[y][0][z]=1&x[y][0][v][w]=2'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
'1'
,
'v'
:
{
'w'
:
'2'
}
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work for ---'
,
function
(
)
{
var
str
=
'x[y][0][z]=1&x[y][1][z]=2'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
'1'
}
,
{
'z'
:
'2'
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work for ----'
,
function
(
)
{
var
str
=
'x[y][0][z]=1&x[y][0][w]=a&x[y][1][z]=2&x[y][1][w]=3'
;
var
obj
=
{
'x'
:
{
'y'
:
[
{
'z'
:
'1'
,
'w'
:
'a'
}
,
{
'z'
:
'2'
,
'w'
:
'3'
}
]
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should work for first and lastname of a user'
,
function
(
)
{
var
str
=
'user[name][first]=tj&user[name][last]=holowaychuk'
;
var
obj
=
{
user
:
{
name
:
{
first
:
'tj'
,
last
:
'holowaychuk'
}
}
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
}
)
;
describe
(
'errors'
,
function
(
)
{
it
(
'should get a error for string'
,
function
(
)
{
var
input
=
'foo=bar'
;
try
{
qs
.
stringify
(
input
)
;
}
catch
(
e
)
{
expect
(
e
.
message
)
.
to
.
eql
(
'stringify expects an object'
)
;
}
}
)
;
it
(
'should get a error for array'
,
function
(
)
{
var
input
=
[
'foo'
,
'bar'
]
;
try
{
qs
.
stringify
(
input
)
;
}
catch
(
e
)
{
expect
(
e
.
message
)
.
to
.
eql
(
'stringify expects an object'
)
;
}
}
)
;
it
(
'should get a error for null'
,
function
(
)
{
var
input
=
null
;
try
{
qs
.
stringify
(
input
)
;
}
catch
(
e
)
{
expect
(
e
.
message
)
.
to
.
eql
(
'stringify expects an object'
)
;
}
}
)
;
}
)
;
describe
(
'numbers'
,
function
(
)
{
it
(
'should use numbers in arrays'
,
function
(
)
{
var
str
=
'limit[0]=1&limit[1]=2&limit[2]=3'
;
var
obj
=
{
limit
:
[
1
,
2
,
3
]
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
it
(
'should use numbers in objects'
,
function
(
)
{
var
str
=
'limit=1'
;
var
obj
=
{
limit
:
1
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
}
)
;
describe
(
'others'
,
function
(
)
{
it
(
'should work with a date'
,
function
(
)
{
var
date
=
new
Date
(
0
)
;
var
str
=
'at='
+
encodeURIComponent
(
date
)
var
obj
=
{
at
:
date
}
;
expect
(
qs
.
stringify
(
obj
)
)
.
to
.
eql
(
str
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL