From e2a3f354ff453d08b4473441a8e9213d064ae87d Mon Sep 17 00:00:00 2001 From: meixg Date: Fri, 3 Mar 2023 14:35:04 +0800 Subject: [PATCH] debugger: fix behavior of { a: 1 } in the debugger repl fix: #46808 --- lib/internal/debugger/inspect_repl.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index b4f454152dc438..1f8e6af4f45845 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -573,8 +573,16 @@ function createRepl(inspector) { if (input === '\n') return lastCommand; // Add parentheses: exec process.title => exec("process.title"); const match = RegExpPrototypeExec(/^\s*(?:exec|p)\s+([^\n]*)/, input); + input = match ? match[1] : input; + + // Add parentheses to make sure input is parsed as expression + if (RegExpPrototypeExec(/^\s*{/, input) !== null && + RegExpPrototypeExec(/;\s*$/, input) === null) { + input = `(${StringPrototypeTrim(input)})\n`; + } + if (match) { - lastCommand = `exec(${JSONStringify(match[1])})`; + lastCommand = `exec(${JSONStringify(input)})`; } else { lastCommand = input; }