[XFA] Fix an hidden issue in the FormCalc lexer

Since there are no script engine with XFA, the FormCalc parser is not used irl.
The bug @nmtigor noticed was hidden by another one (the wrong check on `match`).
This commit is contained in:
Calixte Denizet 2022-09-20 13:53:50 +02:00
parent 8dd2b48488
commit f5b835157b
2 changed files with 5 additions and 3 deletions

View File

@ -239,8 +239,8 @@ class Lexer {
getNumber(first) {
const match = this.data.substring(this.pos).match(numberPattern);
if (!match) {
return first - 0x30 /* = 0 */;
if (!match[0]) {
return new Token(TOKEN.number, first - 0x30 /* = 0 */);
}
const number = parseFloat(
this.data.substring(this.pos - 1, this.pos + match[0].length)

View File

@ -22,8 +22,10 @@ describe("FormCalc expression parser", function () {
describe("FormCalc lexer", function () {
it("should lex numbers", function () {
const lexer = new Lexer(
"12 1.2345 .7 .12345 1e-2 1.2E+3 1e2 1.2E3 nan 12. 2.e3 infinity 99999999999999999 123456789.012345678 9e99999"
"1 7 12 1.2345 .7 .12345 1e-2 1.2E+3 1e2 1.2E3 nan 12. 2.e3 infinity 99999999999999999 123456789.012345678 9e99999"
);
expect(lexer.next()).toEqual(new Token(TOKEN.number, 1));
expect(lexer.next()).toEqual(new Token(TOKEN.number, 7));
expect(lexer.next()).toEqual(new Token(TOKEN.number, 12));
expect(lexer.next()).toEqual(new Token(TOKEN.number, 1.2345));
expect(lexer.next()).toEqual(new Token(TOKEN.number, 0.7));