Skip to content

Commit 33cd844

Browse files
committed
Auto-generated commit
1 parent 44a64a2 commit 33cd844

11 files changed

Lines changed: 646 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-11-08)
7+
## Unreleased (2026-11-10)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`0a22d73`](https://github.com/stdlib-js/stdlib/commit/0a22d737a2f828ebf30c8ea8ba1952d1bed155c7) - add `utils/json-pointer/base/assert/is-safe-token` [(#16320)](https://github.com/stdlib-js/stdlib/pull/16320)
14+
15+
</section>
16+
17+
<!-- /.features -->
818

919
<section class="bug-fixes">
1020

@@ -35,6 +45,7 @@ A total of 10 issues were closed in this release:
3545

3646
<details>
3747

48+
- [`0a22d73`](https://github.com/stdlib-js/stdlib/commit/0a22d737a2f828ebf30c8ea8ba1952d1bed155c7) - **feat:** add `utils/json-pointer/base/assert/is-safe-token` [(#16320)](https://github.com/stdlib-js/stdlib/pull/16320) _(by Gururaj Gurram, Athan Reines)_
3849
- [`a3ef833`](https://github.com/stdlib-js/stdlib/commit/a3ef8332fc0b02f15802a6edb81df0ede5457fc6) - **fix:** add support for `d`, `s`, `u`, and `v` regexp flags [(#16543)](https://github.com/stdlib-js/stdlib/pull/16543) _(by Rajan Pantha)_
3950
- [`78ad2fa`](https://github.com/stdlib-js/stdlib/commit/78ad2fa5dbb12ce808dec93197d5343745ff91b8) - **docs:** normalize trailing newlines in REPL help texts [(#16420)](https://github.com/stdlib-js/stdlib/pull/16420) _(by Philipp Burckhardt)_
4051
- [`c075755`](https://github.com/stdlib-js/stdlib/commit/c075755477fee5aed33b7ad976072bb428f60bc3) - **chore:** update keywords and fix type [(#16329)](https://github.com/stdlib-js/stdlib/pull/16329) _(by Philipp Burckhardt)_
@@ -68,10 +79,11 @@ A total of 10 issues were closed in this release:
6879

6980
### Contributors
7081

71-
A total of 13 people contributed to this release. Thank you to the following contributors:
82+
A total of 14 people contributed to this release. Thank you to the following contributors:
7283

7384
- Andrey Rodrigues
7485
- Athan Reines
86+
- Gururaj Gurram
7587
- Jean Carlos Vargas
7688
- Krishna Sharma
7789
- Manit Roy
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isSafeToken
22+
23+
> Test whether a JSON Pointer reference token is safe.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
This function tests whether a [JSON Pointer][json-pointer] reference token is safe to use for property traversal. Tokens matching `__proto__`, `constructor`, or `prototype` are considered unsafe as they are common prototype pollution vectors.
30+
31+
</section>
32+
33+
<!-- /.intro -->
34+
35+
<!-- Package usage documentation. -->
36+
37+
<section class="usage">
38+
39+
## Usage
40+
41+
```javascript
42+
var isSafeToken = require( '@stdlib/utils/json-pointer/base/assert/is-safe-token' );
43+
```
44+
45+
#### isSafeToken( token )
46+
47+
Tests whether a JSON Pointer reference token is safe.
48+
49+
```javascript
50+
var bool = isSafeToken( 'foo' );
51+
// returns true
52+
53+
bool = isSafeToken( '__proto__' );
54+
// returns false
55+
56+
bool = isSafeToken( 'constructor' );
57+
// returns false
58+
59+
bool = isSafeToken( 'prototype' );
60+
// returns false
61+
```
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
68+
69+
<section class="notes">
70+
71+
</section>
72+
73+
<!-- /.notes -->
74+
75+
<!-- Package usage examples. -->
76+
77+
<section class="examples">
78+
79+
## Examples
80+
81+
<!-- eslint no-undef: "error" -->
82+
83+
```javascript
84+
var isSafeToken = require( '@stdlib/utils/json-pointer/base/assert/is-safe-token' );
85+
86+
var bool = isSafeToken( 'foo' );
87+
// returns true
88+
89+
bool = isSafeToken( '0' );
90+
// returns true
91+
92+
bool = isSafeToken( '-' );
93+
// returns true
94+
95+
bool = isSafeToken( '__proto__' );
96+
// returns false
97+
98+
bool = isSafeToken( 'constructor' );
99+
// returns false
100+
101+
bool = isSafeToken( 'prototype' );
102+
// returns false
103+
```
104+
105+
</section>
106+
107+
<!-- /.examples -->
108+
109+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
110+
111+
<section class="references">
112+
113+
</section>
114+
115+
<!-- /.references -->
116+
117+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
118+
119+
<section class="related">
120+
121+
</section>
122+
123+
<!-- /.related -->
124+
125+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
126+
127+
<section class="links">
128+
129+
[json-pointer]: https://tools.ietf.org/html/rfc6901
130+
131+
</section>
132+
133+
<!-- /.links -->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var isSafeToken = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var values;
33+
var out;
34+
var v;
35+
var i;
36+
37+
values = [
38+
'foo',
39+
'bar',
40+
'__proto__',
41+
'constructor',
42+
'prototype',
43+
'0',
44+
'-',
45+
'baz'
46+
];
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
v = values[ i % values.length ];
51+
out = isSafeToken( v );
52+
if ( typeof out !== 'boolean' ) {
53+
b.fail( 'should return a boolean' );
54+
}
55+
}
56+
b.toc();
57+
if ( !isBoolean( out ) ) {
58+
b.fail( 'should return a boolean' );
59+
}
60+
b.pass( 'benchmark finished' );
61+
b.end();
62+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{alias}}( token )
3+
Tests whether a JSON Pointer reference token is safe.
4+
5+
Parameters
6+
----------
7+
token: string
8+
JSON Pointer reference token.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating whether a token is safe.
14+
15+
Examples
16+
--------
17+
> var bool = {{alias}}( 'foo' )
18+
true
19+
> bool = {{alias}}( '0' )
20+
true
21+
> bool = {{alias}}( '-' )
22+
true
23+
> bool = {{alias}}( '__proto__' )
24+
false
25+
> bool = {{alias}}( 'constructor' )
26+
false
27+
> bool = {{alias}}( 'prototype' )
28+
false
29+
30+
See Also
31+
--------
32+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Tests whether a JSON Pointer reference token is safe.
23+
*
24+
* @param token - reference token
25+
* @returns boolean indicating whether a token is safe
26+
*
27+
* @example
28+
* var bool = isSafeToken( 'foo' );
29+
* // returns true
30+
*
31+
* @example
32+
* var bool = isSafeToken( '__proto__' );
33+
* // returns false
34+
*
35+
* @example
36+
* var bool = isSafeToken( 'constructor' );
37+
* // returns false
38+
*
39+
* @example
40+
* var bool = isSafeToken( 'prototype' );
41+
* // returns false
42+
*/
43+
declare function isSafeToken( token: string ): boolean;
44+
45+
46+
// EXPORTS //
47+
48+
export = isSafeToken;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import isSafeToken = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isSafeToken( 'foo' ); // $ExpectType boolean
27+
isSafeToken( '__proto__' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided a value other than a string...
31+
{
32+
isSafeToken( true ); // $ExpectError
33+
isSafeToken( false ); // $ExpectError
34+
isSafeToken( null ); // $ExpectError
35+
isSafeToken( undefined ); // $ExpectError
36+
isSafeToken( 5 ); // $ExpectError
37+
isSafeToken( [] ); // $ExpectError
38+
isSafeToken( {} ); // $ExpectError
39+
isSafeToken( ( x: number ): number => x ); // $ExpectError
40+
}
41+
42+
// The compiler throws an error if the function is provided an unsupported number of arguments...
43+
{
44+
isSafeToken(); // $ExpectError
45+
isSafeToken( 'foo', 123 ); // $ExpectError
46+
}

0 commit comments

Comments
 (0)