From ca3c7fda642105783428ff53e7ea55137e4f89f8 Mon Sep 17 00:00:00 2001 From: ihsangan Date: Sat, 8 Jun 2024 10:16:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=20handling=20when=20undefined=20value=20or?= =?UTF-8?q?=20contain=20escape=20string=20Finally!!=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 7422273..9aa62c7 100644 --- a/index.js +++ b/index.js @@ -228,19 +228,21 @@ async function serveResult(request) { let dc = new URL(request.url).searchParams.get('decode') let code = 200 let result = await callAPI(request) - if (result.name.includes(`undefined`)) { + if (result.name != undefined) { + result.name = result.name.replace(/\u002B/g, '%20') + if (dc == false) { + result = result + } + if (!dc || dc == true) { + result.name = decodeURIComponent(result.name) + } + } + else if (result.name = undefined) { result = {success:false,message:"Not found"} } if (result.success == false) { code = 400 } - result.name = result.name.replace(/\u002B/g, '%20') - if (dc == false) { - result = result - } - if (!dc || dc == true) { - result.name = decodeURIComponent(result.name) - } let response = new Response(JSON.stringify(result), { status: code, headers: {