summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWeijia Wang <starkwang@126.com>2018-06-27 12:57:57 +0800
committerWeijia Wang <381152119@qq.com>2018-07-02 23:04:04 +0800
commit4f151228472d80a4583f90aeeaaec1bdc4446fe0 (patch)
treed7b85ad5814190583770a2a65ed8ee0e84f3d4e3 /lib
parent484c6c31b068fb64fa8b4bd46b82bc09a54a6a17 (diff)
downloadandroid-node-v8-4f151228472d80a4583f90aeeaaec1bdc4446fe0.tar.gz
android-node-v8-4f151228472d80a4583f90aeeaaec1bdc4446fe0.tar.bz2
android-node-v8-4f151228472d80a4583f90aeeaaec1bdc4446fe0.zip
repl: fix tab completion for object properties with special char
The old RegExp will pass property names like `"hello world!"` when filtering the results of tab complete. This change is to fix it. Fixes: https://github.com/nodejs/node/issues/21201 PR-URL: https://github.com/nodejs/node/pull/21556 Fixes: https://github.com/nodejs/node/issues/21201 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/repl.js28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/repl.js b/lib/repl.js
index 6b5f480387..6345c742f6 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -47,6 +47,10 @@ const {
makeRequireFunction,
addBuiltinLibsToObject
} = require('internal/modules/cjs/helpers');
+const {
+ isIdentifierStart,
+ isIdentifierChar
+} = require('internal/deps/acorn/dist/acorn');
const internalUtil = require('internal/util');
const { isTypedArray } = require('internal/util/types');
const util = require('util');
@@ -900,9 +904,25 @@ const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/;
const simpleExpressionRE =
/(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/;
-function intFilter(item) {
- // filters out anything not starting with A-Z, a-z, $ or _
- return /^[A-Za-z_$]/.test(item);
+function isIdentifier(str) {
+ if (str === '') {
+ return false;
+ }
+ const first = str.codePointAt(0);
+ if (!isIdentifierStart(first)) {
+ return false;
+ }
+ const firstLen = first > 0xffff ? 2 : 1;
+ for (var i = firstLen; i < str.length; i += 1) {
+ const cp = str.codePointAt(i);
+ if (!isIdentifierChar(cp)) {
+ return false;
+ }
+ if (cp > 0xffff) {
+ i += 1;
+ }
+ }
+ return true;
}
const ARRAY_LENGTH_THRESHOLD = 1e6;
@@ -932,7 +952,7 @@ function filteredOwnPropertyNames(obj) {
return fakeProperties;
}
- return Object.getOwnPropertyNames(obj).filter(intFilter);
+ return Object.getOwnPropertyNames(obj).filter(isIdentifier);
}
function getGlobalLexicalScopeNames(contextId) {