Skip to content

Commit

Permalink
fix: __proto__ copy (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored Dec 31, 2021
1 parent ddefb57 commit aa332a5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 30 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node-version: [6, 8, 10, 12, 14, 16]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout Git Source
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm i -g npminstall@latest-3 && npminstall

- name: Continuous Integration
run: npm run ci

- name: Code Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions appveyor.yml

This file was deleted.

2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module.exports = function extend() {

// Extend the base object
for (name in options) {
if (name === '__proto__') continue;

src = target[name];
copy = options[name];

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"dependencies": {},
"devDependencies": {
"covert": "^1.1.0",
"egg-ci": "^1.5.0",
"eslint": "^3.2.2",
"eslint-config-egg": "^3.2.0",
"tape": "^4.6.0"
Expand All @@ -35,6 +34,7 @@
"index.js"
],
"ci": {
"version": "4, 6, 7"
"type": "github",
"version": "6, 8, 10, 12, 14, 16"
}
}
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,18 @@ test('works without Array.isArray', function (t) {
Array.isArray = savedIsArray;
t.end();
});

test('fix __proto__ copy', function (t) {
var r = extend(true, {}, JSON.parse('{"__proto__": {"polluted": "yes"}}'));
t.deepEqual(
JSON.stringify(r),
'{}',
'It should not copy __proto__'
);
t.deepEqual(
''.polluted,
undefined,
'It should not affect object prototype'
);
t.end();
});

0 comments on commit aa332a5

Please sign in to comment.