Skip to content

Commit df7e737

Browse files
committed
Auto-generated commit
1 parent 8300f2d commit df7e737

6 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎CHANGELOG.md‎

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

7-
## Unreleased (2026-11-12)
7+
## Unreleased (2026-11-17)
88

99
<section class="features">
1010

@@ -51,6 +51,7 @@ A total of 10 issues were closed in this release:
5151

5252
<details>
5353

54+
- [`d00c253`](https://github.com/stdlib-js/stdlib/commit/d00c25388d3c73d6fe3a272540e6686a4a86bb19) - **refactor:** add error handling for invalid escape sequences [(#16677)](https://github.com/stdlib-js/stdlib/pull/16677) _(by Gururaj Gurram)_
5455
- [`4ce7668`](https://github.com/stdlib-js/stdlib/commit/4ce7668d098bf469feb7d67026e2480fc26de84a) - **docs:** update throws annotations [(#16597)](https://github.com/stdlib-js/stdlib/pull/16597) _(by Philipp Burckhardt, Athan Reines)_
5556
- [`a6aa6d9`](https://github.com/stdlib-js/stdlib/commit/a6aa6d97df92d15c0262526367502ebd9d367036) - **feat:** add `utils/json-pointer/has` [(#16246)](https://github.com/stdlib-js/stdlib/pull/16246) _(by Gururaj Gurram, Athan Reines)_
5657
- [`6514036`](https://github.com/stdlib-js/stdlib/commit/6514036b042522b853e8c77111fc8b7c2eaf42cc) - **feat:** add `utils/json-pointer/get` [(#16245)](https://github.com/stdlib-js/stdlib/pull/16245) _(by Gururaj Gurram, Athan Reines)_

‎json-pointer/parse/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ tokens = parse( '' );
5656
- Per [RFC 6901][rfc-6901], an empty string refers to the root of the document, and, thus, the function returns an empty array `[]`.
5757
- Non-empty pointers must begin with a `/` character.
5858
- Escape sequences are decoded. During decoding, `~1` is unescaped to `/` before `~0` is unescaped to `~`.
59+
- If a pointer contains an invalid escape sequence (i.e., a `~` character not followed by `0` or `1`), the function throws an error.
5960

6061
</section>
6162

‎json-pointer/parse/docs/repl.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
Escape sequences are decoded. During decoding, `~1` is unescaped to `/`
99
before `~0` is unescaped to `~`.
1010

11+
If a pointer contains an invalid escape sequence (i.e., a `~` character not
12+
followed by `0` or `1`), the function throws an error.
13+
1114
Parameters
1215
----------
1316
pointer: string

‎json-pointer/parse/docs/types/index.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*
3030
* @param pointer - JSON Pointer string
3131
* @throws input argument must be either empty or start with a `/` character
32+
* @throws input argument must not contain invalid escape sequences
3233
* @returns array of reference tokens
3334
*
3435
* @example

‎json-pointer/parse/lib/main.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ var replace = require( '@stdlib/string/base/replace' );
2525
var format = require( '@stdlib/string/format' );
2626

2727

28+
// VARIABLES //
29+
30+
var RE_INVALID_ESCAPE = /~(?![01])/;
31+
32+
2833
// MAIN //
2934

3035
/**
@@ -39,6 +44,7 @@ var format = require( '@stdlib/string/format' );
3944
* @param {string} pointer - JSON Pointer string
4045
* @throws {TypeError} must provide a string
4146
* @throws {Error} pointer must be empty or start with a `/` character
47+
* @throws {Error} pointer must not contain invalid escape sequences
4248
* @returns {Array<string>} array of unescaped reference tokens
4349
*
4450
* @example
@@ -68,6 +74,10 @@ function parse( pointer ) {
6874
if ( pointer.charAt( 0 ) !== '/' ) {
6975
throw new Error( format( 'invalid argument. Must provide either an empty string or a string starting with a `/` character. Value: `%s`.', pointer ) );
7076
}
77+
// Per RFC 6901, `~` is only valid as part of the escape sequences `~0` and `~1`:
78+
if ( RE_INVALID_ESCAPE.test( pointer ) ) {
79+
throw new Error( format( 'invalid argument. A `~` character must be followed by either `0` or `1`. Value: `%s`.', pointer ) );
80+
}
7181

7282
tokens = pointer.split( '/' );
7383
tokens = tokens.slice( 1 );

‎json-pointer/parse/test/test.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ tape( 'the function throws an error if pointer does not start with `/`', functio
8080
}
8181
});
8282

83+
tape( 'the function throws an error if provided a pointer containing an invalid escape sequence', function test( t ) {
84+
var values;
85+
var i;
86+
87+
values = [
88+
'/foo~bar',
89+
'/foo~',
90+
'/~2',
91+
'/foo~/bar',
92+
'/~a'
93+
];
94+
for ( i = 0; i < values.length; i++ ) {
95+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
96+
}
97+
t.end();
98+
99+
function badValue( value ) {
100+
return function badValue() {
101+
parse( value );
102+
};
103+
}
104+
});
105+
83106
tape( 'the function returns an empty array for the root pointer ("")', function test( t ) {
84107
var tokens = parse( '' );
85108
t.deepEqual( tokens, [], 'returns expected value' );

0 commit comments

Comments
 (0)