repl: don't interpret floating point numbers
authorBen Noordhuis <info@bnoordhuis.nl>
Sat, 10 Nov 2012 17:21:13 +0000 (18:21 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Sat, 10 Nov 2012 17:21:17 +0000 (18:21 +0100)
Don't interpret floating point numbers, e.g. ".1234", as REPL commands.

Fixes #4268.

lib/repl.js
test/simple/test-repl.js

index 624a09c..55df83f 100644 (file)
@@ -206,7 +206,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
 
     // Check to see if a REPL keyword was used. If it returns true,
     // display next prompt and return.
-    if (cmd && cmd.charAt(0) === '.') {
+    if (cmd && cmd.charAt(0) === '.' && cmd != parseFloat(cmd)) {
       var matches = cmd.match(/^(\.[^\s]+)\s*(.*)$/);
       var keyword = matches && matches[1];
       var rest = matches && matches[2];
index aeca81c..d03cccc 100644 (file)
@@ -119,6 +119,9 @@ function error_test() {
     // You can recover with the .break command
     { client: client_unix, send: '.break',
       expect: prompt_unix },
+    // Floating point numbers are not interpreted as REPL commands.
+    { client: client_unix, send: '.1234',
+      expect: '0.1234' },
     // Can parse valid JSON
     { client: client_unix, send: 'JSON.parse(\'{"valid": "json"}\');',
       expect: '{ valid: \'json\' }'},