Remove the need for parethesis for JSONPath filter selectors

As per official proposed standard:
https://www.rfc-editor.org/rfc/rfc9535.html#name-filter-selector
This commit is contained in:
Raymond Hill 2025-03-30 13:57:04 -04:00
parent cdb1afc3b2
commit 9adedbc30e
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -147,7 +147,7 @@ export class JSONPath {
#CHILDREN = 3;
#DESCENDANTS = 4;
#reUnquotedIdentifier = /^[A-Za-z_][\w]*|^\*/;
#reExpr = /^([!=^$*]=|[<>]=?)(.+?)\)\]/;
#reExpr = /^([!=^$*]=|[<>]=?)(.+?)\]/;
#reIndice = /^-?\d+/;
#root;
#compiled;
@ -192,15 +192,15 @@ export class JSONPath {
continue;
}
// Bracket accessor syntax
if ( query.startsWith('[?(', i) ) {
const not = query.charCodeAt(i+3) === 0x21 /* ! */;
const j = i + 3 + (not ? 1 : 0);
if ( query.startsWith('[?', i) ) {
const not = query.charCodeAt(i+2) === 0x21 /* ! */;
const j = i + 2 + (not ? 1 : 0);
const r = this.#compile(query, j);
if ( r === undefined ) { return; }
if ( query.startsWith(')]', r.i) === false ) { return; }
if ( query.startsWith(']', r.i) === false ) { return; }
if ( not ) { r.steps.at(-1).not = true; }
steps.push({ mv: mv || this.#CHILDREN, steps: r.steps });
i = r.i + 2;
i = r.i + 1;
mv = this.#UNDEFINED;
continue;
}