You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by vh...@apache.org on 2014/07/24 10:39:27 UTC

svn commit: r1613039 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java

Author: vhennebert
Date: Thu Jul 24 08:39:27 2014
New Revision: 1613039

URL: http://svn.apache.org/r1613039
Log:
XGC-86: DSCParser always throws DSCException %%EOF not found when checkEOF is false
Patch by Teon Metselaar, applied with minor changes + a test case

Added:
    xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java   (with props)
Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java?rev=1613039&r1=1613038&r2=1613039&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/dsc/DSCParser.java Thu Jul 24 08:39:27 2014
@@ -205,9 +205,6 @@ public class DSCParser implements DSCPar
                 handler.line(getLine());
                 break;
             case EOF:
-                if (isCheckEOF()) {
-                    this.eofFound = true;
-                }
                 handler.endDocument();
                 break;
             default:
@@ -295,12 +292,12 @@ public class DSCParser implements DSCPar
     protected void parseNext() throws IOException, DSCException {
         String line = readLine();
         if (line != null) {
-            if (eofFound && (line.length() > 0)) {
+            if (isCheckEOF() && eofFound && (line.length() > 0)) {
                 throw new DSCException("Content found after EOF");
             }
             if (line.startsWith("%%")) {
                 DSCComment comment = parseDSCLine(line);
-                if (comment.getEventType() == EOF && isCheckEOF()) {
+                if (comment.getEventType() == EOF) {
                     this.eofFound = true;
                 }
                 this.nextEvent = comment;

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java?rev=1613039&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java Thu Jul 24 08:39:27 2014
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.ps.dsc;
+
+import java.io.ByteArrayInputStream;
+
+import org.junit.Test;
+
+public class DSCParserTestCase {
+
+    private final String correctDSC
+            = "%!PS-Adobe-3.0\n"
+            + "%%LanguageLevel: 3\n"
+            + "%%EOF";
+
+    private final String spuriousContentAfterEOF
+            = "%!PS-Adobe-3.0\n"
+            + "%%LanguageLevel: 3\n"
+            + "%%EOF\n"
+            + "%%SpuriousContent";
+
+    @Test
+    public void eofDetectedWhenCheckEOFEnabled() throws Exception {
+        parseDSC(correctDSC, true);
+    }
+
+    @Test
+    public void eofDetectedWhenCheckEOFDisabled() throws Exception {
+        parseDSC(correctDSC, false);
+    }
+
+    @Test(expected = DSCException.class)
+    public void spuriousContentDetected() throws Exception {
+        parseDSC(spuriousContentAfterEOF, true);
+    }
+
+    @Test
+    public void spuriousContentIgnored() throws Exception {
+        parseDSC(spuriousContentAfterEOF, false);
+    }
+
+    private void parseDSC(String dsc, boolean checkEOF) throws Exception {
+        DSCParser parser = new DSCParser(new ByteArrayInputStream(dsc.getBytes("US-ASCII")));
+        parser.setCheckEOF(checkEOF);
+        while (parser.hasNext()) {
+            parser.next();
+        }
+    }
+
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/dsc/DSCParserTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org