fix: enhance isBalanced function to correctly count quote pairs (#40001)

- issue: #39999

Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
SimFG 2025-02-19 20:19:00 +08:00 committed by GitHub
parent fd701eca71
commit aba39ff98f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -281,8 +281,6 @@ Currently, the objects injected by expr include: <code>param</code>, <code>proxy
function isBalanced(input) {
const stack = [];
const pairs = {
"'": "'",
'"': '"',
'(': ')',
'[': ']',
'{': '}',
@ -298,8 +296,18 @@ Currently, the objects injected by expr include: <code>param</code>, <code>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;
}
</script>
</body>