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.
This commit is contained in:
Jonas Jenwald 2018-06-19 09:12:24 +02:00
parent 3b07147d98
commit df4799a12a
2 changed files with 12 additions and 8 deletions

View File

@ -734,16 +734,16 @@ var Lexer = (function LexerClosure() {
} else if (ch === 0x2B) { // '+' } else if (ch === 0x2B) { // '+'
ch = this.nextChar(); ch = this.nextChar();
} }
if (ch === 0x2E) { // '.'
divideBy = 10;
ch = this.nextChar();
}
if (ch === 0x0A || ch === 0x0D) { // LF, CR if (ch === 0x0A || ch === 0x0D) { // LF, CR
// Ignore line-breaks (this is consistent with Adobe Reader). // Ignore line-breaks (this is consistent with Adobe Reader).
do { do {
ch = this.nextChar(); ch = this.nextChar();
} while (ch === 0x0A || ch === 0x0D); } while (ch === 0x0A || ch === 0x0D);
} }
if (ch === 0x2E) { // '.'
divideBy = 10;
ch = this.nextChar();
}
if (ch < 0x30 || ch > 0x39) { // '0' - '9' if (ch < 0x30 || ch > 0x39) { // '0' - '9'
throw new FormatError( throw new FormatError(
`Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`); `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`);

View File

@ -58,11 +58,15 @@ describe('parser', function() {
it('should ignore line-breaks between operator and digit in number', it('should ignore line-breaks between operator and digit in number',
function() { function() {
var input = new StringStream('-\r\n205.88'); let minusInput = new StringStream('-\r\n205.88');
var lexer = new Lexer(input); let minusLexer = new Lexer(minusInput);
var result = lexer.getNumber();
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() { it('should handle glued numbers and operators', function() {