Merge pull request #6695 from Snuffleupagus/issue-6692

Ensure that `Lexer_getName` does not fail if a `Name` contains in invalid usage of the NUMBER SIGN (#) (issue 6692)
This commit is contained in:
Yury Delendik 2015-12-01 10:25:57 -06:00
commit 4a82f2f5fd
4 changed files with 42 additions and 4 deletions

View File

@ -832,17 +832,32 @@ var Lexer = (function LexerClosure() {
return strBuf.join(''); return strBuf.join('');
}, },
getName: function Lexer_getName() { getName: function Lexer_getName() {
var ch; var ch, previousCh;
var strBuf = this.strBuf; var strBuf = this.strBuf;
strBuf.length = 0; strBuf.length = 0;
while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) { while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
if (ch === 0x23) { // '#' if (ch === 0x23) { // '#'
ch = this.nextChar(); 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); var x = toHexDigit(ch);
if (x !== -1) { if (x !== -1) {
var x2 = toHexDigit(this.nextChar()); previousCh = ch;
ch = this.nextChar();
var x2 = toHexDigit(ch);
if (x2 === -1) { 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)); strBuf.push(String.fromCharCode((x << 4) | x2));
} else { } else {

View File

@ -0,0 +1 @@
http://web.archive.org/web/20151126121615/http://www.inf.ufg.br/~hugoribeiro/OSPs/osp-im.pdf

View File

@ -817,6 +817,15 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue6692",
"file": "pdfs/issue6692.pdf",
"md5": "ba078e0ddd59cda4b6c51ea10599f49a",
"link": true,
"rounds": 1,
"firstPage": 11,
"lastPage": 11,
"type": "eq"
},
{ "id": "devicen", { "id": "devicen",
"file": "pdfs/devicen.pdf", "file": "pdfs/devicen.pdf",
"md5": "aac6a91725435d1376c6ff492dc5cb75", "md5": "aac6a91725435d1376c6ff492dc5cb75",

View File

@ -1,4 +1,4 @@
/* globals expect, it, describe, StringStream, Lexer, Linearization */ /* globals expect, it, describe, StringStream, Lexer, Name, Linearization */
'use strict'; 'use strict';
@ -77,6 +77,19 @@ describe('parser', function() {
expect(result).toEqual('ABCD'); expect(result).toEqual('ABCD');
}); });
it('should handle Names with invalid usage of NUMBER SIGN (#)', function() {
var inputNames = ['/# 680 0 R', '/#AQwerty', '/#A<</B'];
var expectedNames = ['#', '#AQwerty', '#A'];
for (var i = 0, ii = inputNames.length; i < ii; i++) {
var input = new StringStream(inputNames[i]);
var lexer = new Lexer(input);
var result = lexer.getName();
expect(result).toEqual(Name.get(expectedNames[i]));
}
});
}); });
describe('Linearization', function() { describe('Linearization', function() {