Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .github/workflows/ci-module.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: ci

on:
push:
branches:
- master
pull_request:
workflow_dispatch:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
test:
uses: hapijs/.github/.github/workflows/ci-module.yml@master
with:
min-node-version: 14
test:
uses: hapijs/.github/.github/workflows/ci-module.yml@min-node-22-hapi-21
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**/node_modules
**/package-lock.json

coverage.*
coverage/

**/.DS_Store
**/._*
Expand Down
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ iterated on and values copied, the `__proto__` property leaks and becomes the ob
### `Bourne.parse(text, [reviver], [options])`

Parses a given JSON-formatted text into an object where:

- `text` - the JSON text string.
- `reviver` - the `JSON.parse()` optional `reviver` argument.
- `options` - optional configuration object where:
Expand All @@ -37,6 +38,7 @@ Parses a given JSON-formatted text into an object where:
### `Bourne.scan(obj, [options])`

Scans a given object for prototype properties where:

- `obj` - the object being scanned.
- `options` - optional configuration object where:
- `protoAction` - optional string with one of:
Expand Down
37 changes: 11 additions & 26 deletions benchmarks/ignore.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
'use strict';

const Benchmark = require('benchmark');
const Bourne = require('..');
import { Bench } from 'tinybench';

import * as Bourne from '../src/index.js';

const internals = {
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }',
};

internals.reviver = function (key, value) {
return value;
};

const suite = new Benchmark.Suite();

const bench = new Bench();

suite
bench
.add('JSON.parse', () => {

JSON.parse(internals.text);
})
.add('Bourne.parse', () => {

Bourne.parse(internals.text, { protoAction: 'ignore' });
})
.add('reviver', () => {

JSON.parse(internals.text, internals.reviver);
})
.on('cycle', (event) => {
});

console.log(String(event.target));
})
.on('complete', function () {

console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });


internals.reviver = function (key, value) {

return value;
};
await bench.run();

console.table(bench.table());
43 changes: 15 additions & 28 deletions benchmarks/no__proto__.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
'use strict';

const Benchmark = require('benchmark');
const Bourne = require('..');
import { Bench } from 'tinybench';

import * as Bourne from '../src/index.js';

const internals = {
text: '{ "a": 5, "b": 6, "proto": { "x": 7 }, "c": { "d": 0, "e": "text", "\\u005f\\u005fproto": { "y": 8 }, "f": { "g": 2 } } }',
suspectRx: /"(?:_|\\u005f)(?:_|\\u005f)(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006f)(?:t|\\u0074)(?:o|\\u006f)(?:_|\\u005f)(?:_|\\u005f)"/
suspectRx:
/"(?:_|\\u005f)(?:_|\\u005f)(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006f)(?:t|\\u0074)(?:o|\\u006f)(?:_|\\u005f)(?:_|\\u005f)"/,
};

internals.reviver = function (key, value) {
if (key.match(internals.suspectRx)) {
return undefined;
}

const suite = new Benchmark.Suite();
return value;
};

const bench = new Bench();

suite
bench
.add('JSON.parse', () => {

JSON.parse(internals.text);
})
.add('Bourne.parse', () => {

Bourne.parse(internals.text);
})
.add('reviver', () => {

JSON.parse(internals.text, internals.reviver);
})
.on('cycle', (event) => {
});

console.log(String(event.target));
})
.on('complete', function () {
await bench.run();

console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });


internals.reviver = function (key, value) {

if (key.match(internals.suspectRx)) {
return undefined;
}

return value;
};
console.table(bench.table());
43 changes: 14 additions & 29 deletions benchmarks/remove.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
'use strict';

const Benchmark = require('benchmark');
const Bourne = require('..');
import { Bench } from 'tinybench';

import * as Bourne from '../src/index.js';

const internals = {
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }',
};

internals.reviver = function (key, value) {
if (key === '__proto__') {
return undefined;
}

const suite = new Benchmark.Suite();
return value;
};

const bench = new Bench();

suite
bench
.add('JSON.parse', () => {

JSON.parse(internals.text);
})
.add('Bourne.parse', () => {

Bourne.parse(internals.text, { protoAction: 'remove' });
})
.add('reviver', () => {

JSON.parse(internals.text, internals.reviver);
})
.on('cycle', (event) => {

console.log(String(event.target));
})
.on('complete', function () {

console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });


internals.reviver = function (key, value) {
});

if (key === '__proto__') {
return undefined;
}

return value;
};
await bench.run();

console.table(bench.table());
54 changes: 18 additions & 36 deletions benchmarks/throw.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,43 @@
'use strict';

const Benchmark = require('benchmark');
const Bourne = require('..');
import { Bench } from 'tinybench';

import * as Bourne from '../src/index.js';

const internals = {
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }',
invalid: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } } }'
invalid:
'{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } } }',
};

internals.reviver = function (key, value) {
if (key === '__proto__') {
throw new Error('kaboom');
}

const suite = new Benchmark.Suite();
return value;
};

const bench = new Bench();

suite
bench
.add('JSON.parse', () => {

JSON.parse(internals.text);
})
.add('JSON.parse error', () => {

try {
JSON.parse(internals.invalid);
}
catch (ignoreErr) { }
} catch {}
})
.add('Bourne.parse', () => {

try {
Bourne.parse(internals.text);
}
catch (ignoreErr) { }
} catch {}
})
.add('reviver', () => {

try {
JSON.parse(internals.text, internals.reviver);
}
catch (ignoreErr) { }
})
.on('cycle', (event) => {
} catch {}
});

console.log(String(event.target));
})
.on('complete', function () {

console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });


internals.reviver = function (key, value) {

if (key === '__proto__') {
throw new Error('kaboom');
}

return value;
};
await bench.run();

console.table(bench.table());
62 changes: 0 additions & 62 deletions lib/index.d.ts

This file was deleted.

8 changes: 8 additions & 0 deletions oxfmt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DefaultOxfmtConfig from '@hapi/oxc-plugin/oxfmt';
import { defineConfig } from 'oxfmt';

import type { OxfmtConfig } from 'oxfmt';

export default defineConfig({
...DefaultOxfmtConfig,
}) as OxfmtConfig;
11 changes: 11 additions & 0 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import HapiRecommended from '@hapi/oxc-plugin/oxlint';
import { defineConfig } from 'oxlint';

import type { OxlintConfig } from 'oxlint';

export default defineConfig({
extends: [HapiRecommended],
env: {
...HapiRecommended.env,
},
}) as OxlintConfig;
Loading
Loading