From e5732f489d27f40b125714f88d2a8279dbcddd32 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Wed, 18 Apr 2012 09:48:28 -0700 Subject: [PATCH 1/2] Handle junk at the end of postscript functions. --- src/function.js | 5 ++++- test/unit/function_spec.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/function.js b/src/function.js index 2e7ad45e6..d16805b52 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 2a1dc0b75..94240c47d 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() { From 6ab7584ba46283f1542567c7424c95ddbe5bdfe9 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Wed, 18 Apr 2012 09:50:47 -0700 Subject: [PATCH 2/2] Fix to lowercase. --- src/function.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/function.js b/src/function.js index d16805b52..56b405ede 100644 --- a/src/function.js +++ b/src/function.js @@ -839,7 +839,7 @@ var PostScriptLexer = (function PostScriptLexerClosure() { ch = stream.lookChar(); if (ch === null) break; - ch.toLowerCase(); + ch = ch.toLowerCase(); if (ch >= 'a' && ch <= 'z') str += ch; else