# HG changeset patch # User Jiri Vanek # Date 1452165463 -3600 # Node ID 97d5dcfd9ec0ec9c6b1ea16431b6ea2d18704277 # Parent 486f0dc7b5caa0632d9aef8601e460a780b2d642 fixed R2690 - Can't run BOM into JNLP file diff -r 486f0dc7b5ca -r 97d5dcfd9ec0 ChangeLog --- 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 + + 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 Fixed typo in javadoc generation diff -r 486f0dc7b5ca -r 97d5dcfd9ec0 NEWS --- 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 diff -r 486f0dc7b5ca -r 97d5dcfd9ec0 netx/net/sourceforge/nanoxml/XMLElement.java --- 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; + } + + + } diff -r 486f0dc7b5ca -r 97d5dcfd9ec0 tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java --- 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)); + } } diff -r 486f0dc7b5ca -r 97d5dcfd9ec0 tests/netx/unit/net/sourceforge/jnlp/templates/EFBBBF.jnlp --- /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 @@ + + + + + + EFBBBF bytes starting with file + IcedTea + + + File starting with xml BOM EFBBBF bytes + + + + + + + + +