changeset 1281:97d5dcfd9ec0

fixed R2690 - Can't run BOM into JNLP file
author Jiri Vanek <jvanek@redhat.com>
date Thu, 07 Jan 2016 12:17:43 +0100
parents 486f0dc7b5ca
children 0d9faf51357d
files ChangeLog NEWS netx/net/sourceforge/nanoxml/XMLElement.java tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java tests/netx/unit/net/sourceforge/jnlp/templates/EFBBBF.jnlp
diffstat 5 files changed, 152 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jan 06 17:34:03 2016 +0100
+++ b/ChangeLog	Thu Jan 07 12:17:43 2016 +0100
@@ -1,3 +1,17 @@
+2016-01-07  Jiri Vanek  <jvanek@redhat.com>
+
+	BOM character now dont cause error
+	* netx/net/sourceforge/nanoxml/XMLElement.java: duplicated whitespace recognition
+	code moved to isRegularWhiteSpace.  First call to scanWhitespace repalced by
+	call to scanLeadingWhitespace. New field BOM introduced. (scanWhitespace)
+	made private, and uses isRegularWhiteSpace. (scanLeadingWhitespace) new method,
+	same as scanWhitespacebut also skipps BOM and marks it.
+	* tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java: Added tests to
+	issue
+	* tests/netx/unit/net/sourceforge/jnlp/templates/EFBBBF.jnlp: new file. jnlp
+	file starting with bom.
+	* NEWS: mentioned PR2690
+
 2016-01-06  James Le Cuirot <chewi@gentoo.org>
 
 	Fixed typo in javadoc generation
--- a/NEWS	Wed Jan 06 17:34:03 2016 +0100
+++ b/NEWS	Thu Jan 07 12:17:43 2016 +0100
@@ -12,6 +12,7 @@
 * all connection restrictions now consider also port
 * PR2779: html-gen.sh: Don't try to call hg if .hg directory isn't present
 * PR2591 - IcedTea-Web request resources twice for meta informations and causes ClientAbortException on tomcat in conjunction with JnlpDownloadServlet
+* PR2690 - Can't run BOM into JNLP file
 * NetX
   - main-class attribute trimmed by default
   - in strict mode, main-class attribute checked for invalid characters
--- a/netx/net/sourceforge/nanoxml/XMLElement.java	Wed Jan 06 17:34:03 2016 +0100
+++ b/netx/net/sourceforge/nanoxml/XMLElement.java	Thu Jan 07 12:17:43 2016 +0100
@@ -195,6 +195,11 @@
      * Character read too much for the comment remover.
      */
     private char sanitizeCharReadTooMuch;
+    
+   /**
+     * Whether the BOM header appeared
+     */
+    private boolean BOM = false;
 
     /**
      * The reader provided by the caller of the parse method.
@@ -494,7 +499,7 @@
         this.parserLineNr = startingLineNr;
 
         for (;;) {
-            char ch = this.scanWhitespace();
+            char ch = this.scanLeadingWhitespace();
 
             if (ch != '<') {
                 throw this.expectedInput("<", ch);
@@ -584,24 +589,50 @@
         }
     }
 
+    private boolean isRegularWhiteSpace(char ch) {
+        switch (ch) {
+            case ' ':
+            case '\t':
+            case '\n':
+            case '\r':
+                return true;
+            default:
+                return false;
+        }
+    }
+    
     /**
      * This method scans an identifier from the current reader.
      *
      * @return the next character following the whitespace.
      * @throws java.io.IOException if something goes wrong
      */
-    protected char scanWhitespace()
+    private char scanWhitespace()
             throws IOException {
-        for (;;) {
+        while(true) {
             char ch = this.readChar();
-            switch (ch) {
-                case ' ':
-                case '\t':
-                case '\n':
-                case '\r':
-                    break;
-                default:
-                    return ch;
+            if (!isRegularWhiteSpace(ch)) {
+                return ch;
+            }
+        }
+    }
+     /**
+     * This method scans an leading identifier from the current reader.
+     * 
+     * UNlike scanWhitespace, it skipps also BOM
+     *
+     * @return the next character following the whitespace.
+     * @throws java.io.IOException if something goes wrong
+     */
+    private char scanLeadingWhitespace()
+            throws IOException {
+        while(true) {
+            char ch = this.readChar();
+            //this is BOM , not space
+            if (ch == '') {
+                BOM = true;
+            } else if (!isRegularWhiteSpace(ch)) {
+                return ch;
             }
         }
     }
@@ -621,18 +652,17 @@
      */
     protected char scanWhitespace(StringBuffer result)
             throws IOException {
-        for (;;) {
+        while (true) {
             char ch = this.readChar();
-            switch (ch) {
-                case ' ':
-                case '\t':
-                case '\n':
-                    result.append(ch);
-                    break;
-                case '\r':
-                    break;
-                default:
-                    return ch;
+            if (!isRegularWhiteSpace(ch)) {
+                return ch;
+            } else {
+                switch (ch) {
+                    case ' ':
+                    case '\t':
+                    case '\n':
+                        result.append(ch);
+                }
             }
         }
     }
@@ -1297,4 +1327,11 @@
 
         }
     }
+
+    public boolean isBOM() {
+        return BOM;
+    }
+    
+    
+    
 }
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java	Wed Jan 06 17:34:03 2016 +0100
+++ b/tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java	Thu Jan 07 12:17:43 2016 +0100
@@ -42,7 +42,10 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.IOException;
+import net.sourceforge.jnlp.annotations.Bug;
 import net.sourceforge.jnlp.annotations.KnownToFail;
+import net.sourceforge.jnlp.util.FileUtils;
+import org.junit.Assert;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -105,5 +108,21 @@
         String malformedJnlp = originalJnlp.replace("'jnlp.jnlp'", "jnlp.jnlp");
         Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true, false));
     }
+    
+    
+    @Bug(id = "PR2690")
+    @Test
+    public void testXmlBomTagSoupOff() throws ParseException {
+        InputStream is = this.getClass().getClassLoader().getResourceAsStream("net/sourceforge/jnlp/templates/EFBBBF.jnlp");
+        Assert.assertNotNull(is);
+        Parser.getRootNode(is, new ParserSettings(false, true, false));
+    }
+
+    @Test
+    public void testXmlBomTagSoupOn() throws ParseException {
+        InputStream is = this.getClass().getClassLoader().getResourceAsStream("net/sourceforge/jnlp/templates/EFBBBF.jnlp");
+        Assert.assertNotNull(is);
+        Parser.getRootNode(is, new ParserSettings(false, true, true));
+    }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/netx/unit/net/sourceforge/jnlp/templates/EFBBBF.jnlp	Thu Jan 07 12:17:43 2016 +0100
@@ -0,0 +1,59 @@
+<!--
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+
+ -->
+<!--
+This file is starting with EF BB BF bytes,
+but depends on your editor if yu can see them as  or not at all.
+I fnot, use hexaeditor to verify
+-->
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp spec="1.0" href="EFBBBF.jnlp" codebase=".">
+  <information>
+    <title>EFBBBF bytes starting with file</title>
+    <vendor>IcedTea</vendor>
+    <homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
+<!-- see http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=2690-->
+    <description>File starting with xml BOM EFBBBF bytes</description>
+    <offline/>
+  </information>
+  <resources>
+    <j2se version="1.4+"/>
+    <jar href="simpletest1.jar"/>
+  </resources>
+  <application-desc main-class="SimpleTest1">
+  </application-desc>
+</jnlp>