From 5382deaa184e0ec68a50e720963fdefc8269dbd2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 14 Apr 2016 02:21:49 +0200 Subject: [PATCH] =?UTF-8?q?repl:=20don=E2=80=99t=20complete=20non-simple?= =?UTF-8?q?=20expressions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the regular expression that recognizes “simple” JS expressions to requiring that the full line needs to match it. Previously, in terms like `a().b.`, `b.` would be a partial match. This meant that completion would evaluate `b` and either fail with a `ReferenceError` or, if `b` was some global, return the properties of the global `b` object. PR-URL: https://github.com/nodejs/node/pull/6192 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis --- lib/repl.js | 2 +- test/parallel/test-repl-tab-complete.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index 1291ad2d072f97..e11d91d8c16fbc 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -627,7 +627,7 @@ ArrayStream.prototype.write = function() {}; const requireRE = /\brequire\s*\(['"](([\w\.\/-]+\/)?([\w\.\/-]*))/; const simpleExpressionRE = - /(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/; + /^\s*(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/; function intFilter(item) { // filters out anything not starting with A-Z, a-z, $ or _ diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index b1aa6d61f4f462..27179472d00d00 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -251,3 +251,11 @@ testMe.complete('obj.', common.mustCall(function(error, data) { assert.strictEqual(data[0].indexOf('obj.1a'), -1); assert.notStrictEqual(data[0].indexOf('obj.a'), -1); })); + +// Don't try to complete results of non-simple expressions +putIn.run(['.clear']); +putIn.run(['function a() {}']); + +testMe.complete('a().b.', common.mustCall((error, data) => { + assert.deepEqual(data, [[], undefined]); +}));