From df4799a12ab990b64e421a3e0b179ed3fcfd82bc Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 19 Jun 2018 09:12:24 +0200 Subject: [PATCH] Ensure that line-breaks are *only* skipped after operators in `Lexer.getNumber` (PR 8359 follow-up) With the current code line-breaks are accepted not just after an operator, but after a decimal point as well. When looking at this again, the latter case seems prone to cause false positives and might also interfere with subsequent patches. Hence this is code is adjusted to actually do what the original commit message says, and nothing more. --- src/core/parser.js | 8 ++++---- test/unit/parser_spec.js | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/parser.js b/src/core/parser.js index c383a7656..84d17f798 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -734,16 +734,16 @@ var Lexer = (function LexerClosure() { } else if (ch === 0x2B) { // '+' ch = this.nextChar(); } - if (ch === 0x2E) { // '.' - divideBy = 10; - ch = this.nextChar(); - } if (ch === 0x0A || ch === 0x0D) { // LF, CR // Ignore line-breaks (this is consistent with Adobe Reader). do { ch = this.nextChar(); } while (ch === 0x0A || ch === 0x0D); } + if (ch === 0x2E) { // '.' + divideBy = 10; + ch = this.nextChar(); + } if (ch < 0x30 || ch > 0x39) { // '0' - '9' throw new FormatError( `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`); diff --git a/test/unit/parser_spec.js b/test/unit/parser_spec.js index 95fa81ef6..86e775c88 100644 --- a/test/unit/parser_spec.js +++ b/test/unit/parser_spec.js @@ -58,11 +58,15 @@ describe('parser', function() { it('should ignore line-breaks between operator and digit in number', function() { - var input = new StringStream('-\r\n205.88'); - var lexer = new Lexer(input); - var result = lexer.getNumber(); + let minusInput = new StringStream('-\r\n205.88'); + let minusLexer = new Lexer(minusInput); - expect(result).toEqual(-205.88); + expect(minusLexer.getNumber()).toEqual(-205.88); + + let plusInput = new StringStream('+\r\n205.88'); + let plusLexer = new Lexer(plusInput); + + expect(plusLexer.getNumber()).toEqual(205.88); }); it('should handle glued numbers and operators', function() {