From f5b835157b4493db9955418596c7934eef22f6c6 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 20 Sep 2022 13:53:50 +0200 Subject: [PATCH] [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`). --- src/core/xfa/formcalc_lexer.js | 4 ++-- test/unit/xfa_formcalc_spec.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/xfa/formcalc_lexer.js b/src/core/xfa/formcalc_lexer.js index fd7123d73..d6a4eafae 100644 --- a/src/core/xfa/formcalc_lexer.js +++ b/src/core/xfa/formcalc_lexer.js @@ -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) diff --git a/test/unit/xfa_formcalc_spec.js b/test/unit/xfa_formcalc_spec.js index 748353425..94f18d63a 100644 --- a/test/unit/xfa_formcalc_spec.js +++ b/test/unit/xfa_formcalc_spec.js @@ -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));