REPL: dot-commands produce SyntaxError inside multi-line input
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 冷清
- 技術堆疊
- javascript, nodejs
- 領域
- cli
研究方向
從 lib/repl.js 開始,重點關注 Recoverable-error 路徑、kAddNewLineOnTTY 和 onLine(cmd) 處理程序。使用 node -i 和提供的 printf 命令重現問題,然後追蹤緩衝的多行輸入如何到達點命令檢查。完成的標準是:.break、.clear、.exit 和 .help 能在多行輸入中運作,且不會產生 SyntaxError。
由索引模型根據 Issue 內容生成。
描述
Version
any v24.1.0+
Platform
Tested on:
Microsoft Windows NT 10.0.19045.0 x64;
WSL2 Debian;
Subsystem
REPL
What steps will reproduce the bug?
printf "function a() {\n.break\n" | node -i
printf "function a() {\n.exit\n" | node -i
printf "function a() {\n.help\n" | node -i
How often does it reproduce? Is there a required condition?
Always. Required condition: any registered dot-command typed as the first line after a Recoverable error if self.terminal === true. This includes both real interactive TTYs and node -i with piped stdin.
What is the expected behavior? Why is that the expected behavior?
Welcome to Node.js v24.0.2.
Type ".help" for more information.
> function a() {
| .exit
Welcome to Node.js v24.0.2.
Type ".help" for more information.
> function a() {
| .break
>
Welcome to Node.js v24.0.2.
Type ".help" for more information.
> function a() {
| .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.editor Enter editor mode
.exit Exit the REPL
.help Print this help message
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file
Press Ctrl+C to abort current expression, Ctrl+D to exit the REPL
|
What do you see instead?
Welcome to Node.js v24.1.0.
Type ".help" for more information.
> function a() {
| .exit
.exit
^
Uncaught SyntaxError: Unexpected token '.'
Welcome to Node.js v24.1.0.
Type ".help" for more information.
> function a() {
| .break
.break
^
Uncaught SyntaxError: Unexpected token '.'
Welcome to Node.js v24.1.0.
Type ".help" for more information.
> function a() {
| .help
.help
^
Uncaught SyntaxError: Unexpected token '.'
Additional information
The expected behavior is dot-commands working in multi-line mode. Since 24.1.0 they do not. Only changes to TTY multi-line input behavior in 24.1.0 were introduced by #58003.
Bisect:
git checkout v24.1.0
./configure
make -j2 node > /dev/null 2>/dev/null
printf "function a(){\n.break\n" | ./node -i
git checkout 629a954477^
make -j2 node > /dev/null 2>/dev/null
printf "function a(){\n.break\n" | ./node -i
git checkout 629a954477
make -j2 node > /dev/null 2>/dev/null
printf "function a(){\n.break\n" | ./node -i
Hunk level bisect:
git checkout 629a954477
make -j2 node >/dev/null 2>/dev/null
printf "n\nn\nn\nn\ny\nn\n" | git checkout -p 629a954477^ -- lib/repl.js
make -j2 node >/dev/null 2>/dev/null
printf "function a() {\n.break\n" | ./node -i
particular hunk introducing the bug:
@@ -943,33 +941,15 @@ function REPLServer(prompt,
}
// If error was SyntaxError and not JSON.parse error
- if (e) {
- if (e instanceof Recoverable && !sawCtrlD) {
- // Start buffering data like that:
- // {
- // ... x: 1
- // ... }
+ // We can start a multiline command
+ if (e instanceof Recoverable && !sawCtrlD) {
+ if (self.terminal) {
+ self[kAddNewLineOnTTY]();
+ } else {
self[kBufferedCommandSymbol] += cmd + '\n';
self.displayPrompt();
- return;
- }
- }
-
- // In the next two if blocks, we do not use os.EOL instead of '\n'
- // because on Windows it is '\r\n'
- if (StringPrototypeIncludes(cmd, '\n')) { // If you are editing a multiline command
- self.history[0] = self[kNormalizeHistoryLineEndings](cmd, '\n', '\r');
- } else if (self[kBufferedCommandSymbol]) { // If a new multiline command was entered
- // Remove the first N lines from the self.history array
- // where N is the number of lines in the buffered command
-
- const lines = StringPrototypeSplit(self[kBufferedCommandSymbol], '\n');
- self.history = ArrayPrototypeSlice(self.history, lines.length);
- lines[lines.length - 1] = cmd;
- const newHistoryLine = ArrayPrototypeJoin(ArrayPrototypeReverse(lines), '\r');
- if (self.history[0] !== newHistoryLine) {
- ArrayPrototypeUnshift(self.history, newHistoryLine);
}
+ return;
}
if (e) {
Reason:
- The change in handling of
Recoverableerror shifts the TTY multi-line handling intoself[kAddNewLineOnTTY]();. - It causes
onLine(cmd)handler to be called with the whole multi-line buffer incmd. - That results in the REPL keyword check failing - instead of checking the first character in
".break"it checks the first character in"function a() {\r.break". (\nbecomes\rinkAddHistory, not relevant to the bug) - Which leads to REPL keywords being passed to
evalwhere they produceSyntaxError: Unexpected token '.'.
- 主要語言
- JavaScript
- 星號
- 122k
- 分支
- 37.4k
- 平均合併
- 4 天 8 小時
- 30 天內合併 PR
- 297
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
nodejs/node#65994 · 2 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
-
feature request
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
相似的 Issue
-
automation models
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
needs:triage
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
enhancement status: needs triage
難度 2/5 1-3 小時 新手友好度 88/100
mastra-ai/mastra#25508 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
agentic-workflows
難度 1/5 1 小時以內 新手友好度 72/100
githubnext/gh-aw-cao#15017 ·
維護者通常 1 天內回覆