From aba39ff98fbb3150883869630913f9a295029d5a Mon Sep 17 00:00:00 2001 From: SimFG Date: Wed, 19 Feb 2025 20:19:00 +0800 Subject: [PATCH] fix: enhance isBalanced function to correctly count quote pairs (#40001) - issue: #39999 Signed-off-by: SimFG --- internal/http/static/index.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/http/static/index.html b/internal/http/static/index.html index 4f74f1297c..49551383c9 100644 --- a/internal/http/static/index.html +++ b/internal/http/static/index.html @@ -281,8 +281,6 @@ Currently, the objects injected by expr include: param, proxy function isBalanced(input) { const stack = []; const pairs = { - "'": "'", - '"': '"', '(': ')', '[': ']', '{': '}', @@ -298,8 +296,18 @@ Currently, the objects injected by expr include: param, proxy } } } + let countDouble = 0; + let countSingle = 0; - return stack.length === 0; + for (let char of input) { + if (char === '"') { + countDouble += 1; + } else if (char === "'") { + countSingle += 1; + } + } + + return stack.length === 0 && countDouble % 2 === 0 && countSingle % 2 === 0; }