diff --git a/src/core/parser.js b/src/core/parser.js index f36202e97..e43fe09c8 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -832,17 +832,32 @@ var Lexer = (function LexerClosure() { return strBuf.join(''); }, getName: function Lexer_getName() { - var ch; + var ch, previousCh; var strBuf = this.strBuf; strBuf.length = 0; while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) { if (ch === 0x23) { // '#' ch = this.nextChar(); + if (specialChars[ch]) { + warn('Lexer_getName: ' + + 'NUMBER SIGN (#) should be followed by a hexadecimal number.'); + strBuf.push('#'); + break; + } var x = toHexDigit(ch); if (x !== -1) { - var x2 = toHexDigit(this.nextChar()); + previousCh = ch; + ch = this.nextChar(); + var x2 = toHexDigit(ch); if (x2 === -1) { - error('Illegal digit in hex char in name: ' + x2); + warn('Lexer_getName: Illegal digit (' + + String.fromCharCode(ch) +') in hexadecimal number.'); + strBuf.push('#', String.fromCharCode(previousCh)); + if (specialChars[ch]) { + break; + } + strBuf.push(String.fromCharCode(ch)); + continue; } strBuf.push(String.fromCharCode((x << 4) | x2)); } else { diff --git a/test/pdfs/issue6692.pdf.link b/test/pdfs/issue6692.pdf.link new file mode 100644 index 000000000..7b40615cd --- /dev/null +++ b/test/pdfs/issue6692.pdf.link @@ -0,0 +1 @@ +http://web.archive.org/web/20151126121615/http://www.inf.ufg.br/~hugoribeiro/OSPs/osp-im.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 178e2f0b5..054faf0c4 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -817,6 +817,15 @@ "rounds": 1, "type": "eq" }, + { "id": "issue6692", + "file": "pdfs/issue6692.pdf", + "md5": "ba078e0ddd59cda4b6c51ea10599f49a", + "link": true, + "rounds": 1, + "firstPage": 11, + "lastPage": 11, + "type": "eq" + }, { "id": "devicen", "file": "pdfs/devicen.pdf", "md5": "aac6a91725435d1376c6ff492dc5cb75", diff --git a/test/unit/parser_spec.js b/test/unit/parser_spec.js index d05239165..8f4ac785c 100644 --- a/test/unit/parser_spec.js +++ b/test/unit/parser_spec.js @@ -1,4 +1,4 @@ -/* globals expect, it, describe, StringStream, Lexer, Linearization */ +/* globals expect, it, describe, StringStream, Lexer, Name, Linearization */ 'use strict'; @@ -77,6 +77,19 @@ describe('parser', function() { expect(result).toEqual('ABCD'); }); + + it('should handle Names with invalid usage of NUMBER SIGN (#)', function() { + var inputNames = ['/# 680 0 R', '/#AQwerty', '/#A<