diff --git a/lib/util.js b/lib/util.js index 1f810af1..7d106b3c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -74,30 +74,19 @@ function isProtoString(s) { return false; } - /* eslint-disable no-multi-spaces */ - if ( - s.charCodeAt(length - 1) !== 95 /* '_' */ || - s.charCodeAt(length - 2) !== 95 /* '_' */ || - s.charCodeAt(length - 3) !== 111 /* 'o' */ || - s.charCodeAt(length - 4) !== 116 /* 't' */ || - s.charCodeAt(length - 5) !== 111 /* 'o' */ || - s.charCodeAt(length - 6) !== 114 /* 'r' */ || - s.charCodeAt(length - 7) !== 112 /* 'p' */ || - s.charCodeAt(length - 8) !== 95 /* '_' */ || - s.charCodeAt(length - 9) !== 95 /* '_' */ - ) { + if (s.substring(length - 9) !== "__proto__") { return false; } - /* eslint-enable no-multi-spaces */ for (let i = length - 10; i >= 0; i--) { - if (s.charCodeAt(i) !== 36 /* '$' */) { + if (s[i] !== "$") { return false; } } return true; } +exports.isProtoString = isProtoString; function strcmp(aStr1, aStr2) { if (aStr1 === aStr2) { diff --git a/test/test-util.js b/test/test-util.js index 9404f061..6188465d 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -300,3 +300,20 @@ exports["test computeSourceURL"] = function(assert) { "http://example.com/dir/test.js" ); }; + +exports["test isProtoString"] = async function(assert) { + assert.equal(libUtil.isProtoString("a.js"), false); + assert.equal(libUtil.isProtoString("test$__proto__"), false); + assert.equal(libUtil.isProtoString("$$$$$$$$$$$$$dfgdfgdf__proto__"), false); + assert.equal(libUtil.isProtoString("dddddd$$$$$$$$$$$$$__proto__"), false); + assert.equal( + libUtil.isProtoString("$$$$$$$$$$$$$__proto__$$$$$$$$$$$$$__proto__"), + false + ); + assert.equal(libUtil.isProtoString("blabla"), false); + assert.equal(libUtil.isProtoString(""), false); + + assert.equal(libUtil.isProtoString("__proto__"), true); + assert.equal(libUtil.isProtoString("$__proto__"), true); + assert.equal(libUtil.isProtoString("$$$$$$$$$$$$$__proto__"), true); +};