Skip to content

Commit

Permalink
Merge pull request #8359 from Snuffleupagus/Lexer-getNumber-ignore-li…
Browse files Browse the repository at this point in the history
…ne-breaks

Ignore line-breaks between operator and digit in `Lexer.getNumber`
  • Loading branch information
yurydelendik authored May 3, 2017
2 parents 2ac4106 + 40feca1 commit 74ba303
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,14 @@ var Lexer = (function LexerClosure() {
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 < 0x30 || ch > 0x39) { // '0' - '9'
error('Invalid number: ' + String.fromCharCode(ch));
return 0;
error(`Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`);
}

var baseValue = ch - 0x30; // '0'
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/bug1354114.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bug1354114.bmoattachments.org/attachment.cgi?id=8855457
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,14 @@
"link": true,
"type": "eq"
},
{ "id": "bug1354114",
"file": "pdfs/bug1354114.pdf",
"md5": "ad718d04702d29a37792c7f222fe1fa6",
"rounds": 1,
"firstPage": 30,
"link": true,
"type": "eq"
},
{ "id": "issue5874",
"file": "pdfs/issue5874.pdf",
"md5": "25922edf223aa91bc259663d0a34a6ab",
Expand Down
17 changes: 17 additions & 0 deletions test/unit/parser_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ describe('parser', function() {
expect(result).toEqual(-205.88);
});

it('should ignore minus signs in the middle of number', function() {
var input = new StringStream('205--.88');
var lexer = new Lexer(input);
var result = lexer.getNumber();

expect(result).toEqual(205.88);
});

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();

expect(result).toEqual(-205.88);
});

it('should handle glued numbers and operators', function() {
var input = new StringStream('123ET');
var lexer = new Lexer(input);
Expand Down

0 comments on commit 74ba303

Please sign in to comment.