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:
parent
3b07147d98
commit
df4799a12a
@ -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})`);
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user