Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
    >
  • Loading branch information
thefourtheye committed Jul 22, 2015
commit 302fc96a79ac93e3331e7ab6e3b74b959eaab01b
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function REPLServer(prompt,

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

this.commands = {};
this.commands = Object.create(null);
defineDefaultCommands(this);

// figure out which "writer" function to use
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ function error_test() {
// the error message
{ client: client_unix, send: '.invalid_repl_command',
expect: 'Invalid REPL keyword\n' + prompt_unix },
// this makes sure that we don't crash when we use an inherited property as
// a REPL command
{ client: client_unix, send: '.toString',
expect: 'Invalid REPL keyword\n' + prompt_unix },
]);
}

Expand Down