Skip to content

Commit 30edb5a

Browse files
committed
repl: preventing REPL crash with inherited properties
When an inherited property is used as a REPL keyword, the REPL crashes. ➜ Desktop iojs > process.version 'v2.3.4' > .toString readline.js:913 stream[ESCAPE_DECODER].next(r[i]); ^ TypeError: Cannot read property 'call' of undefined at REPLServer.parseREPLKeyword (repl.js:746:15) at REPLServer.<anonymous> (repl.js:284:16) at emitOne (events.js:77:13) at REPLServer.emit (events.js:169:7) at REPLServer.Interface._onLine (readline.js:210:10) at REPLServer.Interface._line (readline.js:549:8) at REPLServer.Interface._ttyWrite (readline.js:826:14) at ReadStream.onkeypress (readline.js:105:10) at emitTwo (events.js:87:13) at ReadStream.emit (events.js:172:7) ➜ Desktop This patch makes the internal `commands` object inherit from `null` so that there will be no inherited properties. > process.version 'v2.3.5-pre' > .toString Invalid REPL keyword > PR-URL: #2163 Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 77fa385 commit 30edb5a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function REPLServer(prompt,
217217

218218
self.setPrompt(prompt !== undefined ? prompt : '> ');
219219

220-
this.commands = {};
220+
this.commands = Object.create(null);
221221
defineDefaultCommands(this);
222222

223223
// figure out which "writer" function to use

test/parallel/test-repl.js

+4
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ function error_test() {
194194
// the error message
195195
{ client: client_unix, send: '.invalid_repl_command',
196196
expect: 'Invalid REPL keyword\n' + prompt_unix },
197+
// this makes sure that we don't crash when we use an inherited property as
198+
// a REPL command
199+
{ client: client_unix, send: '.toString',
200+
expect: 'Invalid REPL keyword\n' + prompt_unix },
197201
]);
198202
}
199203

0 commit comments

Comments
 (0)