Skip to content

Commit e60678b

Browse files
authored
Merge pull request #23 from jg-rp/cts-fixes
Update CTS and fix
2 parents f0608aa + b2686f2 commit e60678b

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# JSON P3 Change Log
22

3-
## Version 1.3.4
3+
## Version 1.3.4 (unreleased)
44

55
**Fixes**
66

77
- Fixed decoding of JSONPath escape sequences (those found in name selectors and string literals). Previously we were relying on `JSON.parse()` to unescape strings, now we have our own `unescapeString()` function that rejects invalid codepoints and surrogate pairs. See [jsonpath-compliance-test-suite #87](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/pull/87).
8+
- Fixed default minimum integer boundary for JSONPath indexes and slice steps. We were off by one.
9+
- Fixed parsing of JSONPath integer literals with an exponent and an upper case 'e'. We now allow 'e' to be upper case.
10+
- Fixed handling of trailing commas in JSONPath bracketed segments. We now raise a syntax error.
11+
- Fixed handling of invalid JSONPath integer and float literals with extra minus signs, leading zeros or too many zeros. We now raise a syntax error in such cases.
812

913
## Version 1.3.3
1014

src/path/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class JSONPathEnvironment {
129129
constructor(options: JSONPathEnvironmentOptions = {}) {
130130
this.strict = options.strict ?? true;
131131
this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
132-
this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) - 1;
132+
this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) + 1;
133133
this.maxRecursionDepth = options.maxRecursionDepth ?? 50;
134134
this.nondeterministic = options.nondeterministic ?? false;
135135
this.keysPattern = options.keysPattern ?? /~/y;

src/path/lex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Token, TokenKind } from "./token";
55

66
// These regular expressions are to be used with Lexer.acceptMatchRun(),
77
// which expects the sticky flag to be set.
8-
const exponentPattern = /e[+-]?\d+/y;
8+
const exponentPattern = /[eE][+-]?\d+/y;
99
const functionNamePattern = /[a-z][a-z_0-9]*/y;
1010
const indexPattern = /-?\d+/y;
1111
const intPattern = /-?[0-9]+/y;

src/path/parse.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export class Parser {
304304
if (stream.peek.kind !== TokenKind.RBRACKET) {
305305
stream.expectPeek(TokenKind.COMMA);
306306
stream.next();
307+
stream.expectPeekNot(TokenKind.RBRACKET, "unexpected trailing comma");
307308
}
308309

309310
stream.next();
@@ -362,7 +363,23 @@ export class Parser {
362363
}
363364

364365
protected parseNumber(stream: TokenStream): NumberLiteral {
365-
return new NumberLiteral(stream.current, Number(stream.current.value));
366+
const value = stream.current.value;
367+
if (value.startsWith("0") && value.length > 1) {
368+
throw new JSONPathSyntaxError(
369+
`invalid number literal '${value}'`,
370+
stream.current,
371+
);
372+
}
373+
374+
const num = Number(stream.current.value);
375+
376+
if (isNaN(num)) {
377+
throw new JSONPathSyntaxError(
378+
`invalid number literal '${value}'`,
379+
stream.current,
380+
);
381+
}
382+
return new NumberLiteral(stream.current, num);
366383
}
367384

368385
protected parsePrefixExpression(stream: TokenStream): PrefixExpression {

src/path/token.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,11 @@ export class TokenStream {
105105
);
106106
}
107107
}
108+
109+
public expectPeekNot(kind: TokenKind, message: string): void {
110+
const peeked = this.peek;
111+
if (peeked.kind === kind) {
112+
throw new JSONPathSyntaxError(message, peeked);
113+
}
114+
}
108115
}

0 commit comments

Comments
 (0)