support set chinese character in header

This commit is contained in:
shalousun 2021-11-12 17:43:34 +08:00
parent 6f1e358c47
commit 302f9b7da7
1 changed files with 16 additions and 1 deletions

View File

@ -182,7 +182,12 @@ function getInputData(element, returnFormDate) {
formData.append(name, $(input)[0].files[0]); formData.append(name, $(input)[0].files[0]);
} else { } else {
const val = $(input).val(); const val = $(input).val();
formData.append(name, val); if (isValidUrl(val)) {
formData.append(name, encodeURI(val));
} else {
// support chinese
formData.append(name, encodeURIComponent(val));
}
} }
} }
}); });
@ -356,3 +361,13 @@ function toCurl(request) {
function isEmpty(obj) { function isEmpty(obj) {
return obj === undefined || obj === null || new String(obj).trim() === ''; return obj === undefined || obj === null || new String(obj).trim() === '';
} }
function isValidUrl(_string) {
let urlString;
try {
urlString = new URL(_string);
} catch (_) {
return false;
}
return urlString.protocol === "http:" || urlString.protocol === "https:" ;
}