From: Brendan Dahl Date: Wed, 18 Apr 2012 16:48:28 +0000 (-0700) Subject: Handle junk at the end of postscript functions. X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e5732f489d27f40b125714f88d2a8279dbcddd32;p=pdf.js.git Handle junk at the end of postscript functions. --- diff --git a/src/function.js b/src/function.js index 2e7ad45..d16805b 100644 --- a/src/function.js +++ b/src/function.js @@ -836,7 +836,10 @@ var PostScriptLexer = (function PostScriptLexerClosure() { // operator var str = ch.toLowerCase(); while (true) { - ch = stream.lookChar().toLowerCase(); + ch = stream.lookChar(); + if (ch === null) + break; + ch.toLowerCase(); if (ch >= 'a' && ch <= 'z') str += ch; else diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js index 2a1dc0b..94240c4 100644 --- a/test/unit/function_spec.js +++ b/test/unit/function_spec.js @@ -77,6 +77,12 @@ describe('function', function() { expect(function() { parse('{'); }).toThrow( new Error('Unexpected symbol: found undefined expected 1.')); }); + it('handles junk after the end', function() { + var number = 3.3; + var program = parse('{ ' + number + ' }#'); + var expectedProgram = [number]; + expect(program).toMatchArray(expectedProgram); + }); }); describe('PostScriptEvaluator', function() {