mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 17:03:34 +00:00
repl: don’t complete non-simple expressions
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 <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
0b1d89f35a
commit
0b66b8f2d2
@ -647,7 +647,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 _
|
||||
|
@ -249,3 +249,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]);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user