Skip to content

Commit b123c23

Browse files
committed
[jsonpath] Increase RFC9535 compliance
Return error on: - unquoted identifier in bracket notation - leading or trailing comma in bracket notation Related feedback: uBlockOrigin/uBlock-issues#4052 (comment)
1 parent 028ffdb commit b123c23

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/js/jsonpath.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,26 @@ export class JSONPath {
437437
}
438438
#consumeIdentifier(query, i) {
439439
const keys = [];
440-
for (;;) {
440+
let needIdentifier = true;
441+
while ( i < query.length ) {
441442
const c0 = query.charCodeAt(i);
442443
if ( c0 === 0x5D /* ] */ ) { break; }
443-
if ( c0 === 0x2C /* , */ || c0 === 0x20 /* SPACE */) {
444+
if ( c0 === 0x20 /* SPACE */ ) {
445+
i += 1;
446+
continue;
447+
}
448+
if ( c0 === 0x2C /* , */ ) {
449+
if ( needIdentifier ) { return; }
444450
i += 1;
451+
needIdentifier = true;
445452
continue;
446453
}
447454
if ( c0 === 0x22 /* " */ || c0 === 0x27 /* ' */ ) {
448455
const r = this.#untilChar(query, c0, i+1);
449456
if ( r === undefined ) { return; }
450457
keys.push(r.s);
451458
i = r.i;
459+
needIdentifier = false;
452460
continue;
453461
}
454462
if ( c0 === 0x2D /* - */ || c0 >= 0x30 && c0 <= 0x39 ) {
@@ -457,13 +465,16 @@ export class JSONPath {
457465
const indice = parseInt(query.slice(i), 10);
458466
keys.push(indice);
459467
i += match[0].length;
468+
needIdentifier = false;
460469
continue;
461470
}
471+
if ( this.#compiled.v2 ) { return; }
462472
const r = this.#consumeUnquotedIdentifier(query, i);
463473
if ( r === undefined ) { return; }
464474
keys.push(r.s);
465475
i = r.i;
466476
}
477+
if ( needIdentifier ) { return; }
467478
return { s: keys.length === 1 ? keys[0] : keys, i };
468479
}
469480
#consumeUnquotedIdentifier(query, i) {

0 commit comments

Comments
 (0)