Skip to content

Commit c7d28e6

Browse files
committed
Add more tests for utils.toQueryString
1 parent d3d96a0 commit c7d28e6

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

build/yea.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@
3535
var value = data[key];
3636
if (Array.isArray(value)) {
3737
for (var i in value) {
38-
segments.push(key + '=' + encodeURIComponent(value[i]));
38+
if (typeof value[i] !== 'undefined') {
39+
if (value[i] === null) {
40+
segments.push(encodeURIComponent(key));
41+
} else {
42+
segments.push(encodeURIComponent(key) + '=' + encodeURIComponent(value[i]));
43+
}
44+
}
3945
}
4046
} else {
41-
segments.push(key + '=' + encodeURIComponent(data[key]));
47+
if (typeof value !== 'undefined') {
48+
if (value === null) {
49+
segments.push(encodeURIComponent(key));
50+
} else {
51+
segments.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
52+
}
53+
}
4254
}
4355
}
4456
return segments.join('&');

build/yea.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@
3535
var value = data[key];
3636
if (Array.isArray(value)) {
3737
for (var i in value) {
38-
segments.push(key + '=' + encodeURIComponent(value[i]));
38+
if (typeof value[i] !== 'undefined') {
39+
if (value[i] === null) {
40+
segments.push(encodeURIComponent(key));
41+
} else {
42+
segments.push(encodeURIComponent(key) + '=' + encodeURIComponent(value[i]));
43+
}
44+
}
3945
}
4046
} else {
41-
segments.push(key + '=' + encodeURIComponent(data[key]));
47+
if (typeof value !== 'undefined') {
48+
if (value === null) {
49+
segments.push(encodeURIComponent(key));
50+
} else {
51+
segments.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
52+
}
53+
}
4254
}
4355
}
4456
return segments.join('&');

0 commit comments

Comments
 (0)