fix: object got query, close #2824

This commit is contained in:
DIYgod
2019-08-11 01:33:33 +08:00
parent 4d9c9c08e7
commit 0aaf1e3f6c
+9 -1
View File
@@ -38,7 +38,15 @@ const custom = got.extend({
options.query = options.query || queryString.stringify(options.params);
}
if (options.query) {
options.query = options.query.replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str));
if (typeof options.query === 'string') {
options.query = options.query.replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str));
} else if (typeof options.query === 'object') {
for (const key in options.query) {
if (typeof options.query[key] === 'string') {
options.query[key] = options.query[key].replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str));
}
}
}
options.searchParams = options.query; // for Got v11 after
}
},