repl: Fixed node repl history edge case.
authorMudit Ameta <zeusdeux@gmail.com>
Tue, 1 Dec 2015 20:49:01 +0000 (02:19 +0530)
committerMyles Borins <mborins@us.ibm.com>
Tue, 19 Jan 2016 19:52:31 +0000 (11:52 -0800)
commitdb0e906fc197f92e5c9f36fef0440946c4c96212
treee6648671187bc80b0fafcdccba2d43b18acf9bd8
parent48564204f01fc39b08a9ba2f4631e32c0d800ead
repl: Fixed node repl history edge case.

If the deprecated NODE_REPL_HISTORY_FILE is set to default
node history file path ($HOME/.node_repl_history) and the file
doesn't exist, then node creates the file and then crashes when
it tries to parse that file as JSON thinking that it's an older
JSON formatted history file. This fixes that bug.

This patch also prevents node repl from throwing if the old
history file is empty or if $HOME/.node_repl_history is empty.

Fixes: https://github.com/nodejs/node/issues/4102
PR-URL: https://github.com/nodejs/node/pull/4108
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
lib/internal/repl.js
test/fixtures/.empty-repl-history-file [new file with mode: 0644]
test/parallel/test-repl-persistent-history.js