Mercurial > hg > release > icedtea-web-1.5
changeset 753:a236aa5f729b
Added tagsup (optional dependence) as sanitizer for (possibly) invalid xml files
line wrap: on
line diff
--- a/ChangeLog Thu Jun 20 17:00:52 2013 +0200 +++ b/ChangeLog Fri Jun 21 12:15:03 2013 +0200 @@ -1,3 +1,33 @@ +2013-06-21 Jiri Vanek <jvanek@redhat.com> + Adam Domurad <adomurad@redhat.com> + Omair Majid <omajid@redhat.com> + + Added tagsup (optional dependence) as sanitizer for (possibly) invalid xml files + * Makefile.am: (LAUNCHER_BOOTCLASSPATH) (PLUGIN_BOOTCLASSPATH) (NETX_CLASSPATH_ARG) + (PLUGIN_COVERAGE_BOOTCLASSPATH) enriched for TAGSOUP_JAR + * acinclude.m4: (IT_CHECK_FOR_TAGSOUP) new macro + * configure.ac: used this new macro + * tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java: + * netx/net/sourceforge/jnlp/JNLPCreator.java: (create) + * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: + * /netx/net/sourceforge/jnlp/JNLPFile.java: (JNLPFile) construcotrs + * netx/net/sourceforge/jnlp/PluginBridge.java + * netx/net/sourceforge/jnlp/Launcher.java: (main) + all adapted to take ParserSettings instead of individual parameters + * netx/net/sourceforge/jnlp/MalformedXMLParser.java: new file, bridge + between tagsoup and our parser + * netx/net/sourceforge/jnlp/XmlParser.java: new file, bridge to old parser + * netx/net/sourceforge/jnlp/Parser.java: refactored to be able both with + * netx/net/sourceforge/jnlp/ParserSettings.java: reworked to serve as + gatherer for various individual parser flags + * netx/net/sourceforge/jnlp/resources/Messages.propertie: (BOXml) + new key describing -xml switch + * tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java: + * tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java: + * tests/netx/unit/net/sourceforge/jnlp/ParserTest.java: + Tests adapted to newest state (both for included/excluded tagsoup) and + new (testTagNotClosedNoTagSoup) (testUnquotedAttributesNoTagSoup) + 2013-06-20 Jiri Vanek <jvanek@redhat.com> Removed out-of date support for jdk 1.5 and older
--- a/Makefile.am Thu Jun 20 17:00:52 2013 +0200 +++ b/Makefile.am Fri Jun 21 12:15:03 2013 +0200 @@ -119,9 +119,9 @@ # IllegalAccessException # - we want full privileges # -export LAUNCHER_BOOTCLASSPATH="-Xbootclasspath/a:$(datadir)/$(PACKAGE_NAME)/netx.jar$(RHINO_RUNTIME)" -export PLUGIN_BOOTCLASSPATH='"-Xbootclasspath/a:$(datadir)/$(PACKAGE_NAME)/netx.jar:$(datadir)/$(PACKAGE_NAME)/plugin.jar$(RHINO_RUNTIME)"' -export PLUGIN_COVERAGE_BOOTCLASSPATH='"-Xbootclasspath/a:$(datadir)/$(PACKAGE_NAME)/netx.jar:$(datadir)/$(PACKAGE_NAME)/plugin.jar$(RHINO_RUNTIME):$(JACOCO_CLASSPATH)"' +export LAUNCHER_BOOTCLASSPATH="-Xbootclasspath/a:$(datadir)/$(PACKAGE_NAME)/netx.jar$(RHINO_RUNTIME):$(TAGSOUP_JAR)" +export PLUGIN_BOOTCLASSPATH='"-Xbootclasspath/a:$(datadir)/$(PACKAGE_NAME)/netx.jar:$(datadir)/$(PACKAGE_NAME)/plugin.jar$(RHINO_RUNTIME):$(TAGSOUP_JAR)"' +export PLUGIN_COVERAGE_BOOTCLASSPATH='"-Xbootclasspath/a:$(datadir)/$(PACKAGE_NAME)/netx.jar:$(datadir)/$(PACKAGE_NAME)/plugin.jar$(RHINO_RUNTIME):$(JACOCO_CLASSPATH):$(TAGSOUP_JAR)"' # Fake update version to work with the Deployment Toolkit script used by Oracle # http://download.oracle.com/javase/tutorial/deployment/deploymentInDepth/depltoolkit_index.html @@ -138,7 +138,15 @@ net.sourceforge.jnlp.security.viewer net.sourceforge.jnlp.services \ net.sourceforge.jnlp.tools net.sourceforge.jnlp.util +NETX_EXCLUDE_SRCS= + # Conditional defintions +if HAVE_TAGSOUP +NETX_CLASSPATH_ARG=-classpath $(TAGSOUP_JAR) +else +NETX_EXCLUDE_SRCS+=net.sourceforge.jnlp.MalformedXMLParser.java +endif + if ENABLE_PLUGIN export ICEDTEAPLUGIN_CLEAN = clean-IcedTeaPlugin export LIVECONNECT_DIR = netscape sun/applet @@ -415,6 +423,7 @@ $(BOOT_DIR)/bin/javac $(IT_JAVACFLAGS) \ -d $(abs_top_builddir)/liveconnect \ -bootclasspath $(NETX_DIR):$(RUNTIME) \ + $(NETX_CLASSPATH_ARG) \ -sourcepath $(LIVECONNECT_SRCS) \ @liveconnect-source-files.txt ; \ fi @@ -445,7 +454,11 @@ # a patch applied to sun.plugin.AppletViewerPanel and generated sources netx-source-files.txt: - find $(NETX_SRCDIR) -name '*.java' | sort > $@ + find $(NETX_SRCDIR) -name '*.java' | sort > $@ ; \ + for src in $(NETX_EXCLUDE_SRCS) ; \ + do \ + sed -i "/$${src}/ d" $@ ; \ + done if !WITH_RHINO sed -i '/RhinoBasedPacEvaluator/ d' $@ endif @@ -459,6 +472,7 @@ -d $(NETX_DIR) \ -sourcepath $(NETX_SRCDIR) \ -bootclasspath $(RUNTIME) \ + $(NETX_CLASSPATH_ARG) \ @netx-source-files.txt (cd $(NETX_RESOURCE_DIR); \ for files in $$(find . -type f); \ @@ -1006,7 +1020,7 @@ mkdir -p $(NETX_UNIT_TEST_DIR) && \ $(BOOT_DIR)/bin/javac $(IT_JAVACFLAGS) \ -d $(NETX_UNIT_TEST_DIR) \ - -classpath $(JUNIT_JAR):$(abs_top_builddir)/liveconnect/lib/classes.jar:$(NETX_DIR)/lib/classes.jar:$(TEST_EXTENSIONS_DIR) \ + -classpath $(JUNIT_JAR):$(abs_top_builddir)/liveconnect/lib/classes.jar:$(NETX_DIR)/lib/classes.jar:$(TEST_EXTENSIONS_DIR):$(TAGSOUP_JAR) \ @netx-unit-tests-source-files.txt && \ mkdir -p stamps && \ touch $@ @@ -1036,7 +1050,7 @@ done ; \ cd $(NETX_UNIT_TEST_DIR) ; \ class_names=`cat $(UNIT_CLASS_NAMES)` ; \ - CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(abs_top_builddir)/liveconnect/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):$(TEST_EXTENSIONS_DIR):.:$(TEST_EXTENSIONS_SRCDIR) \ + CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(abs_top_builddir)/liveconnect/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):$(TEST_EXTENSIONS_DIR):.:$(TEST_EXTENSIONS_SRCDIR):$(TAGSOUP_JAR) \ $(BOOT_DIR)/bin/java -Xbootclasspath:$(RUNTIME) CommandLine $$class_names if WITH_XSLTPROC -$(XSLTPROC) --stringparam logs logs_unit.html $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(NETX_UNIT_TEST_DIR)/tests-output.xml > $(TESTS_DIR)/index_unit.html @@ -1073,6 +1087,9 @@ -cp $(RHINO_RUNTIME) \ -cp $(TEST_EXTENSIONS_DIR) \ -cp $(TEST_EXTENSIONS_SRCDIR) \ +if HAVE_TAGSOUP + -cp $(TAGSOUP_JAR) \ +endif -cp . \ -ix "-org.junit.*" \ -ix "-junit.*" \ @@ -1117,7 +1134,7 @@ mv $(NETX_UNIT_TEST_DIR)/$$file $(NETX_UNIT_TEST_DIR)/"$$file""$(EMMA_BACKUP_SUFFIX)" ; \ done ;\ class_names=`cat $(UNIT_CLASS_NAMES)` ; \ - CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(abs_top_builddir)/liveconnect/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):$(TEST_EXTENSIONS_DIR):$(JACOCO_CLASSPATH):.:$(TEST_EXTENSIONS_SRCDIR) \ + CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(abs_top_builddir)/liveconnect/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):$(TEST_EXTENSIONS_DIR):$(JACOCO_CLASSPATH):.:$(TEST_EXTENSIONS_SRCDIR):$(TAGSOUP_JAR) \ $(BOOT_DIR)/bin/java $(JACOCO_AGENT_SWITCH) -Xbootclasspath:$(RUNTIME) CommandLine $$class_names ; \ for file in $(EMMA_MODIFIED_FILES) ; do \ mv $(NETX_UNIT_TEST_DIR)/$$file $(NETX_UNIT_TEST_DIR)/"$$file""$(EMMA_SUFFIX)" ; \
--- a/NEWS Thu Jun 20 17:00:52 2013 +0200 +++ b/NEWS Fri Jun 21 12:15:03 2013 +0200 @@ -9,9 +9,12 @@ CVE-XXXX-YYYY: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=XXXX-YYYY New in release 1.5 (2013-XX-XX): +* IcedTea-Web now using tagsoup as default (tagsoup dependence) sanitizer for input * JDK older then 1.5 no longer supported * NetX - PR1465 - java.io.FileNotFoundException while trying to download a JAR file + - Netx can now parse malformed jnlp files using tagsoup + - PR1026 - Apps fail to run because of the nanoxml parser's strict XML validation * Plugin - PR854: Resizing an applet several times causes 100% CPU load
--- a/acinclude.m4 Thu Jun 20 17:00:52 2013 +0200 +++ b/acinclude.m4 Fri Jun 21 12:15:03 2013 +0200 @@ -403,6 +403,31 @@ fi ]) +AC_DEFUN_ONCE([IT_CHECK_FOR_TAGSOUP], +[ + AC_MSG_CHECKING([for tagsoup]) + AC_ARG_WITH([tagsoup], + [AS_HELP_STRING([--with-tagsoup], + [tagsoup.jar])], + [ + TAGSOUP_JAR=${withval} + ], + [ + TAGSOUP_JAR= + ]) + if test -z "${TAGSOUP_JAR}"; then + for dir in /usr/share/java /usr/local/share/java ; do + if test -f $dir/tagsoup.jar; then + TAGSOUP_JAR=$dir/tagsoup.jar + break + fi + done + fi + AC_MSG_RESULT(${TAGSOUP_JAR}) + AC_SUBST(TAGSOUP_JAR) + AM_CONDITIONAL([HAVE_TAGSOUP], [test x$TAGSOUP_JAR != xno]) +]) + dnl Generic macro to check for a Java class dnl Takes the name of the class as an argument. The macro name dnl is usually the name of the class with '.'
--- a/configure.ac Thu Jun 20 17:00:52 2013 +0200 +++ b/configure.ac Fri Jun 21 12:15:03 2013 +0200 @@ -111,6 +111,8 @@ IT_FIND_OPTIONAL_JAR([asm], ASM, [/usr/share/java/objectweb-asm4/asm-all.jar /usr/share/java/objectweb-asm4/asm-all-4.0.jar /usr/share/java/objectweb-asm/asm-all.jar]) +IT_CHECK_FOR_TAGSOUP + AC_CONFIG_FILES([jrunscript], [chmod u+x jrunscript]) AC_CONFIG_FILES([build.properties])
--- a/netx/net/sourceforge/jnlp/JNLPCreator.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/JNLPCreator.java Fri Jun 21 12:15:03 2013 +0200 @@ -28,8 +28,8 @@ import net.sourceforge.jnlp.cache.UpdatePolicy; public class JNLPCreator { - public JNLPFile create(URL location, Version version, boolean strict, + public JNLPFile create(URL location, Version version, ParserSettings settings, UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException { - return new JNLPFile(location, version, strict, policy, forceCodebase); + return new JNLPFile(location, version, settings, policy, forceCodebase); } }
--- a/netx/net/sourceforge/jnlp/JNLPFile.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/JNLPFile.java Fri Jun 21 12:15:03 2013 +0200 @@ -67,6 +67,9 @@ /** the network location of this JNLP file */ protected URL fileLocation; + /** the ParserSettings which were used to parse this file */ + protected ParserSettings parserSettings = null; + /** A key that uniquely identifies connected instances (main jnlp+ext) */ protected String uniqueKey = null; @@ -145,7 +148,7 @@ * @throws ParseException if the JNLP file was invalid */ public JNLPFile(URL location) throws IOException, ParseException { - this(location, false); // not strict + this(location, new ParserSettings()); } /** @@ -153,12 +156,12 @@ * default policy. * * @param location the location of the JNLP file - * @param strict whether to enforce the spec when + * @param settings the parser settings to use while parsing the file * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, boolean strict) throws IOException, ParseException { - this(location, (Version) null, strict); + public JNLPFile(URL location, ParserSettings settings) throws IOException, ParseException { + this(location, (Version) null, settings); } /** @@ -167,12 +170,12 @@ * * @param location the location of the JNLP file * @param version the version of the JNLP file - * @param strict whether to enforce the spec when + * @param settings the parser settings to use while parsing the file * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, Version version, boolean strict) throws IOException, ParseException { - this(location, version, strict, JNLPRuntime.getDefaultUpdatePolicy()); + public JNLPFile(URL location, Version version, ParserSettings settings) throws IOException, ParseException { + this(location, version, settings, JNLPRuntime.getDefaultUpdatePolicy()); } /** @@ -186,8 +189,8 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, Version version, boolean strict, UpdatePolicy policy) throws IOException, ParseException { - this(location, version, strict, policy, null); + public JNLPFile(URL location, Version version, ParserSettings settings, UpdatePolicy policy) throws IOException, ParseException { + this(location, version, settings, policy, null); } /** @@ -196,15 +199,16 @@ * * @param location the location of the JNLP file * @param version the version of the JNLP file - * @param strict whether to enforce the spec when + * @param settings the parser settings to use while parsing the file * @param policy the update policy * @param forceCodebase codebase to use if not specified in JNLP file. * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - protected JNLPFile(URL location, Version version, boolean strict, UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException { - Node root = Parser.getRootNode(openURL(location, version, policy)); - parse(root, strict, location, forceCodebase); + protected JNLPFile(URL location, Version version, ParserSettings settings, UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException { + InputStream input = openURL(location, version, policy); + this.parserSettings = settings; + parse(input, location, forceCodebase); //Downloads the original jnlp file into the cache if possible //(i.e. If the jnlp file being launched exist locally, but it @@ -231,13 +235,13 @@ * @param location the location of the JNLP file * @param uniqueKey A string that uniquely identifies connected instances * @param version the version of the JNLP file - * @param strict whether to enforce the spec when + * @param settings the parser settings to use while parsing the file * @param policy the update policy * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(URL location, String uniqueKey, Version version, boolean strict, UpdatePolicy policy) throws IOException, ParseException { - this(location, version, strict, policy); + public JNLPFile(URL location, String uniqueKey, Version version, ParserSettings settings, UpdatePolicy policy) throws IOException, ParseException { + this(location, version, settings, policy); this.uniqueKey = uniqueKey; if (JNLPRuntime.isDebug()) @@ -250,8 +254,9 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(InputStream input, boolean strict) throws ParseException { - this(input, null, strict); + public JNLPFile(InputStream input, ParserSettings settings) throws ParseException { + this.parserSettings = settings; + parse(input, null, null); } /** @@ -263,22 +268,11 @@ * @throws IOException if an IO exception occurred * @throws ParseException if the JNLP file was invalid */ - public JNLPFile(InputStream input, URL codebase, boolean strict) throws ParseException { - parse(Parser.getRootNode(input), strict, null, codebase); + public JNLPFile(InputStream input, URL codebase, ParserSettings settings) throws ParseException { + this.parserSettings = settings; + parse(input, null, codebase); } - /** - * Create a JNLPFile from a character stream. - * - * @param input the stream - * @param strict whether to enforce the spec when - * @throws IOException if an IO exception occurred - * @throws ParseException if the JNLP file was invalid - */ - private JNLPFile(Reader input, boolean strict) throws ParseException { - // todo: now that we are using NanoXML we can use a Reader - //parse(Parser.getRootNode(input), strict, null); - } /** * Open the jnlp file URL from the cache if there, otherwise @@ -338,6 +332,13 @@ } /** + * Returns the ParserSettings that was used to parse this file + */ + public ParserSettings getParserSettings() { + return parserSettings; + } + + /** * Returns the JNLP file's version. */ public Version getFileVersion() { @@ -685,15 +686,16 @@ * from the constructor. * * @param root the root node - * @param strict whether to enforce the spec when + * @param settings the parser settings to use while parsing the file * @param location the file location or null */ - private void parse(Node root, boolean strict, URL location, URL forceCodebase) throws ParseException { + private void parse(InputStream input, URL location, URL forceCodebase) throws ParseException { try { //if (location != null) // location = new URL(location, "."); // remove filename - Parser parser = new Parser(this, location, root, strict, true, forceCodebase); // true == allow extensions + Node root = Parser.getRootNode(input, parserSettings); + Parser parser = new Parser(this, location, root, parserSettings, forceCodebase); // true == allow extensions // JNLP tag information specVersion = parser.getSpecVersion();
--- a/netx/net/sourceforge/jnlp/Launcher.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/Launcher.java Fri Jun 21 12:15:03 2013 +0200 @@ -477,12 +477,12 @@ try { JNLPFile file = null; - file = new JNLPFile(location, parserSettings.isStrict()); + file = new JNLPFile(location, parserSettings); if (fromSource) { // Launches the jnlp file where this file originated. if (file.getSourceLocation() != null) { - file = new JNLPFile(file.getSourceLocation(), parserSettings.isStrict()); + file = new JNLPFile(file.getSourceLocation(), parserSettings); } } return file; @@ -504,9 +504,11 @@ JNLPFile file = null; try { - file = new JNLPFile(location, (Version) null, true, updatePolicy); // strict + ParserSettings settings = new ParserSettings(true, true, false); + file = new JNLPFile(location, (Version) null, settings, updatePolicy); // strict } catch (ParseException ex) { - file = new JNLPFile(location, (Version) null, false, updatePolicy); + ParserSettings settings = new ParserSettings(false, true, true); + file = new JNLPFile(location, (Version) null, settings, updatePolicy); // only here if strict failed but lax did not fail LaunchException lex =
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/MalformedXMLParser.java Fri Jun 21 12:15:03 2013 +0200 @@ -0,0 +1,123 @@ +/* + Copyright (C) 2013 Red Hat, Inc. + +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, version 2. + +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. + */ +package net.sourceforge.jnlp; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +import net.sourceforge.jnlp.runtime.JNLPRuntime; + +import org.ccil.cowan.tagsoup.HTMLSchema; +import org.ccil.cowan.tagsoup.Parser; +import org.ccil.cowan.tagsoup.XMLWriter; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; + +/** + * An specialized {@link XMLParser} that uses TagSoup[1] to parse + * malformed XML + * + * Used by net.sourceforge.jnlp.Parser + * + * [1] http://home.ccil.org/~cowan/XML/tagsoup/ + */ +public class MalformedXMLParser extends XMLParser { + + /** + * Parses the data from an {@link InputStream} to create a XML tree. + * Returns a {@link Node} representing the root of the tree. + * + * @param input the {@link InputStream} to read data from + * @throws ParseException if an exception occurs while parsing the input + */ + @Override + public Node getRootNode(InputStream input) throws ParseException { + if (JNLPRuntime.isDebug()) { + System.out.println("Using MalformedXMLParser"); + } + InputStream xmlInput = xmlizeInputStream(input); + return super.getRootNode(xmlInput); + } + + /** + * Reads malformed XML from the InputStream original and returns a new + * InputStream which can be used to read a well-formed version of the input + * + * @param original + * @return an {@link InputStream} which can be used to read a well-formed + * version of the input XML + * @throws ParseException + */ + private InputStream xmlizeInputStream(InputStream original) throws ParseException { + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + HTMLSchema schema = new HTMLSchema(); + XMLReader reader = new Parser(); + + //TODO walk through the javadoc and tune more settings + //see tagsoup javadoc for details + reader.setProperty(Parser.schemaProperty, schema); + reader.setFeature(Parser.bogonsEmptyFeature, false); + reader.setFeature(Parser.ignorableWhitespaceFeature, true); + reader.setFeature(Parser.ignoreBogonsFeature, false); + + Writer writeger = new OutputStreamWriter(out); + XMLWriter x = new XMLWriter(writeger); + + reader.setContentHandler(x); + + InputSource s = new InputSource(original); + + reader.parse(s); + return new ByteArrayInputStream(out.toByteArray()); + } catch (SAXException e) { + throw new ParseException(R("PBadXML"), e); + } catch (IOException e) { + throw new ParseException(R("PBadXML"), e); + } + + } + +}
--- a/netx/net/sourceforge/jnlp/Parser.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/Parser.java Fri Jun 21 12:15:03 2013 +0200 @@ -1,5 +1,5 @@ // Copyright (C) 2001-2003 Jon A. Maxwell (JAM) -// Copyright (C) 2012 Red Hat, Inc. +// Copyright (C) 2009-2013 Red Hat, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -20,16 +20,14 @@ import static net.sourceforge.jnlp.runtime.Translator.R; import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.*; import java.util.*; -//import javax.xml.parsers.*; // commented to use right Node -//import org.w3c.dom.*; // class for using Tiny XML | NanoXML -//import org.xml.sax.*; -//import gd.xml.tiny.*; + import net.sourceforge.jnlp.UpdateDesc.Check; import net.sourceforge.jnlp.UpdateDesc.Policy; import net.sourceforge.jnlp.runtime.JNLPRuntime; -import net.sourceforge.nanoxml.*; /** * Contains methods to parse an XML document into a JNLPFile. @@ -106,12 +104,11 @@ * @param file the (uninitialized) file reference * @param base if codebase is not specified, a default base for relative URLs * @param root the root node - * @param strict whether to enforce strict compliance with the JNLP spec - * @param allowExtensions whether to allow extensions to the JNLP spec + * @param settings the parser settings to use when parsing the JNLP file * @throws ParseException if the JNLP file is invalid */ - public Parser(JNLPFile file, URL base, Node root, boolean strict, boolean allowExtensions) throws ParseException { - this(file, base, root, strict, allowExtensions, null); + public Parser(JNLPFile file, URL base, Node root, ParserSettings settings) throws ParseException { + this(file, base, root, settings, null); } /** @@ -126,16 +123,15 @@ * @param file the (uninitialized) file reference * @param base if codebase is not specified, a default base for relative URLs * @param root the root node - * @param strict whether to enforce strict compliance with the JNLP spec - * @param allowExtensions whether to allow extensions to the JNLP spec + * @param settings the parser settings to use when parsing the JNLP file * @param codebase codebase to use if we did not parse one from JNLP file. * @throws ParseException if the JNLP file is invalid */ - public Parser(JNLPFile file, URL base, Node root, boolean strict, boolean allowExtensions, URL codebase) throws ParseException { + public Parser(JNLPFile file, URL base, Node root, ParserSettings settings, URL codebase) throws ParseException { this.file = file; this.root = root; - this.strict = strict; - this.allowExtensions = allowExtensions; + this.strict = settings.isStrict(); + this.allowExtensions = settings.isExtensionAllowed(); // ensure it's a JNLP node if (root == null || !root.getNodeName().equals("jnlp")) @@ -1265,116 +1261,33 @@ * * @throws ParseException if the JNLP file is invalid */ - public static Node getRootNode(InputStream input) throws ParseException { - try { - /* SAX - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setValidating(false); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - builder.setErrorHandler(errorHandler); - - Document doc = builder.parse(input); - return doc.getDocumentElement(); - */ - - /* TINY - Node document = new Node(TinyParser.parseXML(input)); - Node jnlpNode = getChildNode(document, "jnlp"); // skip comments - */ - - //A BufferedInputStream is used to allow marking and reseting - //of a stream. - BufferedInputStream bs = new BufferedInputStream(input); + public static Node getRootNode(InputStream input, ParserSettings settings) throws ParseException { + String className = null; + if (settings.isMalformedXmlAllowed()) { + className = "net.sourceforge.jnlp.MalformedXMLParser"; + } else { + className = "net.sourceforge.jnlp.XMLParser"; + } - /* NANO */ - final XMLElement xml = new XMLElement(); - final PipedInputStream pin = new PipedInputStream(); - final PipedOutputStream pout = new PipedOutputStream(pin); - final InputStreamReader isr = new InputStreamReader(bs, getEncoding(bs)); - // Clean the jnlp xml file of all comments before passing - // it to the parser. - new Thread( - new Runnable() { - public void run() { - (new XMLElement()).sanitizeInput(isr, pout); - try { - pout.close(); - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - }).start(); - xml.parseFromReader(new InputStreamReader(pin)); - Node jnlpNode = new Node(xml); - return jnlpNode; - } catch (Exception ex) { - throw new ParseException(R("PBadXML"), ex); + try { + Class<?> klass = null; + try { + klass = Class.forName(className); + } catch (ClassNotFoundException e) { + klass = Class.forName("net.sourceforge.jnlp.XMLParser"); + } + Object instance = klass.newInstance(); + Method m = klass.getMethod("getRootNode", InputStream.class); + + return (Node) m.invoke(instance, input); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof ParseException) { + throw (ParseException)(e.getCause()); + } + throw new ParseException(R("PBadXML"), e); + } catch (Exception e) { + throw new ParseException(R("PBadXML"), e); } } - /** - * Returns the name of the encoding used in this InputStream. - * - * @param input the InputStream - * @return a String representation of encoding - */ - private static String getEncoding(InputStream input) throws IOException { - //Fixme: This only recognizes UTF-8, UTF-16, and - //UTF-32, which is enough to parse the prolog portion of xml to - //find out the exact encoding (if it exists). The reason being - //there could be other encodings, such as ISO 8859 which is 8-bits - //but it supports latin characters. - //So what needs to be done is to parse the prolog and retrieve - //the exact encoding from it. - - int[] s = new int[4]; - String encoding = "UTF-8"; - - //Determine what the first four bytes are and store - //them into an int array. - input.mark(4); - for (int i = 0; i < 4; i++) { - s[i] = input.read(); - } - input.reset(); - - //Set the encoding base on what the first four bytes of the - //inputstream turn out to be (following the information from - //www.w3.org/TR/REC-xml/#sec-guessing). - if (s[0] == 255) { - if (s[1] == 254) { - if (s[2] != 0 || s[3] != 0) { - encoding = "UnicodeLittle"; - } else { - encoding = "X-UTF-32LE-BOM"; - } - } - } else if (s[0] == 254 && s[1] == 255 && (s[2] != 0 || - s[3] != 0)) { - encoding = "UTF-16"; - - } else if (s[0] == 0 && s[1] == 0 && s[2] == 254 && - s[3] == 255) { - encoding = "X-UTF-32BE-BOM"; - - } else if (s[0] == 0 && s[1] == 0 && s[2] == 0 && - s[3] == 60) { - encoding = "UTF-32BE"; - - } else if (s[0] == 60 && s[1] == 0 && s[2] == 0 && - s[3] == 0) { - encoding = "UTF-32LE"; - - } else if (s[0] == 0 && s[1] == 60 && s[2] == 0 && - s[3] == 63) { - encoding = "UTF-16BE"; - } else if (s[0] == 60 && s[1] == 0 && s[2] == 63 && - s[3] == 0) { - encoding = "UTF-16LE"; - } - - return encoding; - } - }
--- a/netx/net/sourceforge/jnlp/ParserSettings.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/ParserSettings.java Fri Jun 21 12:15:03 2013 +0200 @@ -35,7 +35,6 @@ exception statement from your version. */ - package net.sourceforge.jnlp; /** @@ -46,16 +45,34 @@ public class ParserSettings { private final boolean isStrict; + private final boolean extensionAllowed; + private final boolean malformedXmlAllowed; + /** Create a new ParserSettings with the defautl parser settings */ public ParserSettings() { - isStrict = false; + this(false, true, true); } - public ParserSettings(boolean strict) { - isStrict = strict; + /** Create a new ParserSettings object */ + public ParserSettings(boolean strict, boolean extensionAllowed, boolean malformedXmlAllowed) { + this.isStrict = strict; + this.extensionAllowed = extensionAllowed; + this.malformedXmlAllowed = malformedXmlAllowed; } + /** @return true if extensions to the spec are allowed */ + public boolean isExtensionAllowed() { + return extensionAllowed; + } + + /** @return true if parsing malformed xml is allowed */ + public boolean isMalformedXmlAllowed() { + return malformedXmlAllowed; + } + + /** @return true if strict parsing mode is to be used */ public boolean isStrict() { return isStrict; } -} + +} \ No newline at end of file
--- a/netx/net/sourceforge/jnlp/PluginBridge.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/PluginBridge.java Fri Jun 21 12:15:03 2013 +0200 @@ -96,14 +96,15 @@ try { // Use codeBase as the context for the URL. If jnlp_href's // value is a complete URL, it will replace codeBase's context. + ParserSettings defaultSettings = new ParserSettings(); URL jnlp = new URL(codeBase, params.getJNLPHref()); JNLPFile jnlpFile = null; if (params.getJNLPEmbedded() != null) { InputStream jnlpInputStream = new ByteArrayInputStream(decodeBase64String(params.getJNLPEmbedded())); - jnlpFile = new JNLPFile(jnlpInputStream, codeBase, false); + jnlpFile = new JNLPFile(jnlpInputStream, codeBase, defaultSettings); } else { - jnlpFile = jnlpCreator.create(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), codeBase); + jnlpFile = jnlpCreator.create(jnlp, null, defaultSettings, JNLPRuntime.getDefaultUpdatePolicy(), codeBase); } if (jnlpFile.isApplet())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/XmlParser.java Fri Jun 21 12:15:03 2013 +0200 @@ -0,0 +1,183 @@ +/* + Copyright (C) 2013 Red Hat, Inc. + +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, version 2. + +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. + */ + +package net.sourceforge.jnlp; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +import net.sourceforge.nanoxml.XMLElement; + +//import javax.xml.parsers.*; // commented to use right Node +//import org.w3c.dom.*; // class for using Tiny XML | NanoXML +//import org.xml.sax.*; +//import gd.xml.tiny.*; + +/** + * A gateway to the actual implementation of the parsers. + * + * Used by net.sourceforge.jnlp.Parser + */ +class XMLParser { + + /** + * Parses input from an InputStream and returns a Node representing the + * root of the parse tree. + * + * @param input the {@link InputStream} containing the XML + * @return a {@link Node} representing the root of the parsed XML + * @throws ParseException + */ + public Node getRootNode(InputStream input) throws ParseException { + + try { + /* SAX + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setNamespaceAware(true); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(errorHandler); + + Document doc = builder.parse(input); + return doc.getDocumentElement(); + */ + + /* TINY + Node document = new Node(TinyParser.parseXML(input)); + Node jnlpNode = getChildNode(document, "jnlp"); // skip comments + */ + + //A BufferedInputStream is used to allow marking and reseting + //of a stream. + BufferedInputStream bs = new BufferedInputStream(input); + + /* NANO */ + final XMLElement xml = new XMLElement(); + final PipedInputStream pin = new PipedInputStream(); + final PipedOutputStream pout = new PipedOutputStream(pin); + final InputStreamReader isr = new InputStreamReader(bs, getEncoding(bs)); + // Clean the jnlp xml file of all comments before passing + // it to the parser. + new Thread( + new Runnable() { + public void run() { + (new XMLElement()).sanitizeInput(isr, pout); + try { + pout.close(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + }).start(); + xml.parseFromReader(new InputStreamReader(pin)); + Node jnlpNode = new Node(xml); + return jnlpNode; + } catch (Exception ex) { + throw new ParseException(R("PBadXML"), ex); + } + } + + /** + * Returns the name of the encoding used in this InputStream. + * + * @param input the InputStream + * @return a String representation of encoding + */ + private static String getEncoding(InputStream input) throws IOException { + //Fixme: This only recognizes UTF-8, UTF-16, and + //UTF-32, which is enough to parse the prolog portion of xml to + //find out the exact encoding (if it exists). The reason being + //there could be other encodings, such as ISO 8859 which is 8-bits + //but it supports latin characters. + //So what needs to be done is to parse the prolog and retrieve + //the exact encoding from it. + + int[] s = new int[4]; + String encoding = "UTF-8"; + + //Determine what the first four bytes are and store + //them into an int array. + input.mark(4); + for (int i = 0; i < 4; i++) { + s[i] = input.read(); + } + input.reset(); + + //Set the encoding base on what the first four bytes of the + //inputstream turn out to be (following the information from + //www.w3.org/TR/REC-xml/#sec-guessing). + if (s[0] == 255) { + if (s[1] == 254) { + if (s[2] != 0 || s[3] != 0) { + encoding = "UnicodeLittle"; + } else { + encoding = "X-UTF-32LE-BOM"; + } + } + } else if (s[0] == 254 && s[1] == 255 && (s[2] != 0 || + s[3] != 0)) { + encoding = "UTF-16"; + + } else if (s[0] == 0 && s[1] == 0 && s[2] == 254 && + s[3] == 255) { + encoding = "X-UTF-32BE-BOM"; + + } else if (s[0] == 0 && s[1] == 0 && s[2] == 0 && + s[3] == 60) { + encoding = "UTF-32BE"; + + } else if (s[0] == 60 && s[1] == 0 && s[2] == 0 && + s[3] == 0) { + encoding = "UTF-32LE"; + + } else if (s[0] == 0 && s[1] == 60 && s[2] == 0 && + s[3] == 63) { + encoding = "UTF-16BE"; + } else if (s[0] == 60 && s[1] == 0 && s[2] == 63 && + s[3] == 0) { + encoding = "UTF-16LE"; + } + + return encoding; + } +}
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Fri Jun 21 12:15:03 2013 +0200 @@ -189,6 +189,7 @@ BOHeadless = Disables download window, other UIs. BOStrict = Enables strict checking of JNLP file format. BOViewer = Shows the trusted certificate viewer. +BOXml = Uses a strict XML parser to parse the JNLP file. BXnofork = Do not create another JVM. BXclearcache= Clean the JNLP application cache. BXignoreheaders= Skip jar header verification.
--- a/netx/net/sourceforge/jnlp/runtime/Boot.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java Fri Jun 21 12:15:03 2013 +0200 @@ -102,6 +102,7 @@ + " -noupdate " + R("BONoupdate") + "\n" + " -headless " + R("BOHeadless") + "\n" + " -strict " + R("BOStrict") + "\n" + + " -xml " + R("BOXml") + "\n" + " -Xnofork " + R("BXnofork") + "\n" + " -Xclearcache " + R("BXclearcache") + "\n" + " -Xignoreheaders " + R("BXignoreheaders") + "\n" @@ -197,9 +198,18 @@ extra.put("arguments", getOptions("-arg")); extra.put("parameters", getOptions("-param")); extra.put("properties", getOptions("-property")); + boolean strict = false; + boolean malformedXmlAllowed = true; - boolean strict = (null != getOption("-strict")); - ParserSettings settings = new ParserSettings(strict); + if (null != getOption("-strict")) { + strict = true; + } + + if (null != getOption("-xml")) { + malformedXmlAllowed = false; + } + + ParserSettings settings = new ParserSettings(strict, true, malformedXmlAllowed); try { Launcher launcher = new Launcher(false);
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Thu Jun 20 17:00:52 2013 +0200 +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Fri Jun 21 12:15:03 2013 +0200 @@ -76,6 +76,7 @@ import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.NullJnlpFileException; import net.sourceforge.jnlp.ParseException; +import net.sourceforge.jnlp.ParserSettings; import net.sourceforge.jnlp.PluginBridge; import net.sourceforge.jnlp.ResourcesDesc; import net.sourceforge.jnlp.SecurityDesc; @@ -460,7 +461,7 @@ * @param policy the update policy to use when downloading resources * @param mainName Overrides the main class name of the application */ - public static JNLPClassLoader getInstance(URL location, String uniqueKey, Version version, UpdatePolicy policy, String mainName) + public static JNLPClassLoader getInstance(URL location, String uniqueKey, Version version,ParserSettings settings, UpdatePolicy policy, String mainName) throws IOException, ParseException, LaunchException { JNLPClassLoader loader; @@ -469,7 +470,7 @@ loader = uniqueKeyToLoader.get(uniqueKey); if (loader == null || !location.equals(loader.getJNLPFile().getFileLocation())) { - JNLPFile jnlpFile = new JNLPFile(location, uniqueKey, version, false, policy); + JNLPFile jnlpFile = new JNLPFile(location, uniqueKey, version, settings, policy); loader = getInstance(jnlpFile, policy, mainName); } @@ -504,7 +505,7 @@ for (int i = 0; i < ext.length; i++) { try { String uniqueKey = this.getJNLPFile().getUniqueKey(); - JNLPClassLoader loader = getInstance(ext[i].getLocation(), uniqueKey, ext[i].getVersion(), updatePolicy, mainClass); + JNLPClassLoader loader = getInstance(ext[i].getLocation(), uniqueKey, ext[i].getVersion(), file.getParserSettings(), updatePolicy, mainClass); loaderList.add(loader); } catch (Exception ex) { ex.printStackTrace();
--- a/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java Fri Jun 21 12:15:03 2013 +0200 @@ -138,10 +138,10 @@ "</jnlp>"; URL codeBase = new URL("http://www.redhat.com/"); - ; + InputStream is = new ByteArrayInputStream(jnlpContext.getBytes()); - JNLPFile jnlpFile = new JNLPFile(is, codeBase, false); + JNLPFile jnlpFile = new JNLPFile(is, codeBase, new ParserSettings(false,false,false)); Assert.assertEquals("http://icedtea.claspath.org/", jnlpFile.getCodeBase().toExternalForm()); Assert.assertEquals("redhat.embeddedjnlp", jnlpFile.getApplet().getMainClass());
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java Fri Jun 21 12:15:03 2013 +0200 @@ -61,9 +61,10 @@ if (cl == null) { cl = ClassLoader.getSystemClassLoader(); } + ParserSettings defaultParser = new ParserSettings(); InputStream jnlpStream = cl.getResourceAsStream("net/sourceforge/jnlp/basic.jnlp"); - root = Parser.getRootNode(jnlpStream); - parser = new Parser(new DummyJNLPFile(), null, root, false, false); + root = Parser.getRootNode(jnlpStream, defaultParser); + parser = new Parser(new DummyJNLPFile(), null, root, defaultParser); } @Test
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java Fri Jun 21 12:15:03 2013 +0200 @@ -50,6 +50,7 @@ /** Test various corner cases of the parser */ public class ParserCornerCases { + private static final ParserSettings defaultParser = new ParserSettings(false, true,true); @Test public void testCdata() throws ParseException, XMLParseException, IOException { @@ -63,7 +64,7 @@ Assert.assertTrue(target.getContent().contains("DOCTYPE")); Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>")); - Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("argument", node.getNodeName()); String contents = node.getNodeValue(); Assert.assertTrue(contents.contains("xml")); @@ -90,7 +91,7 @@ Assert.assertTrue(target.getContent().contains("DOCTYPE")); Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>")); - Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); node = node.getFirstChild().getFirstChild(); Assert.assertEquals("argument", node.getNodeName()); String contents = node.getNodeValue(); @@ -126,53 +127,36 @@ @Test public void testUnsupportedSpecNumber() throws ParseException { String malformedJnlp = "<?xml?><jnlp spec='11.11'></jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser parser = new Parser(null, null, root, false, false); + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); + Parser parser = new Parser(null, null, root, defaultParser); Assert.assertEquals("11.11", parser.getSpecVersion().toString()); } @Test public void testApplicationAndComponent() throws ParseException { String malformedJnlp = "<?xml?><jnlp><application-desc/><component-desc/></jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser parser = new Parser(null, null, root, false, false); + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); + Parser parser = new Parser(null, null, root, defaultParser); Assert.assertNotNull(parser.getLauncher(root)); } @Test public void testCommentInElements() throws ParseException { String malformedJnlp = "<?xml?><jnlp spec='1.0' <!-- comment -->> </jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser p = new Parser(null, null, root, false, false); + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); + Parser p = new Parser(null, null, root, defaultParser); Assert.assertEquals("1.0", p.getSpecVersion().toString()); } @Test - public void testCommentInElements2() throws ParseException { - String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser p = new Parser(null, null, root, false, false); - Assert.assertEquals("1.0", p.getSpecVersion().toString()); - } - - @Test - @KnownToFail - public void testCommentInAttributes() throws ParseException { - String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser p = new Parser(null, null, root, false, false); - Assert.assertEquals("<!-- something -->", p.getSpecVersion().toString()); - } - - @Test public void testNestedComments() throws ParseException { String malformedJnlp = "<?xml?>" + "<jnlp><information><title>testNestedComments</title>" + "<vendor>IcedTea</vendor><description>" + "<!-- outer <!-- inner --> -->" + "</description></information></jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser p = new Parser(null, null, root, false, false); + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); + Parser p = new Parser(null, null, root, defaultParser); Assert.assertEquals(" -->", p.getInfo(root).get(0).getDescription()); } @@ -186,8 +170,42 @@ " -->\n" + " <information/>" + "</jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); - Parser p = new Parser(null, null, root, false, false); + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), defaultParser); + Parser p = new Parser(null, null, root, defaultParser); + } + + + @Test + public void testCommentInElements2() throws ParseException { + String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>"; + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,true)); + Parser p = new Parser(null, null, root, defaultParser); + //defaultis used + Assert.assertEquals("1.0+", p.getSpecVersion().toString()); } + @Test + public void testCommentInElements2_malformedOff() throws ParseException { + String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>"; + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,false)); + Parser p = new Parser(null, null, root, defaultParser); + Assert.assertEquals("1.0", p.getSpecVersion().toString()); + } + @Test + public void testCommentInAttributes() throws ParseException { + String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>"; + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,true)); + Parser p = new Parser(null, null, root, defaultParser); + Assert.assertEquals("<!-- something -->", p.getSpecVersion().toString()); + } + + + @Test + public void testCommentInAttributes_malformedOff() throws ParseException { + String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>"; + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true,false)); + Parser p = new Parser(null, null, root, defaultParser); + //defaultis used + Assert.assertEquals("1.0+", p.getSpecVersion().toString()); + } }
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java Fri Jun 21 12:15:03 2013 +0200 @@ -51,6 +51,7 @@ public class ParserMalformedXml { private static String originalJnlp = null; + private static ParserSettings lenientParserSettings = new ParserSettings(false, true, true); @BeforeClass public static void setUp() throws IOException { @@ -71,28 +72,38 @@ @Test public void testMissingXmlDecleration() throws ParseException { String malformedJnlp = originalJnlp.replaceFirst("<\\?xml.*\\?>", ""); - Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); + Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); } @Test @KnownToFail public void testMalformedArguments() throws ParseException { String malformedJnlp = originalJnlp.replace("arg2</argument", "arg2<argument"); - Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); + Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); + } + + @Test + public void testTagNotClosed() throws ParseException { + String malformedJnlp = originalJnlp.replace("</jnlp>", "<jnlp>"); + Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); } @Test - @KnownToFail - public void testTagNotClosed() throws ParseException { - String malformedJnlp = originalJnlp.replace("</jnlp>", "<jnlp>"); - Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); + public void testUnquotedAttributes() throws ParseException { + String malformedJnlp = originalJnlp.replace("'jnlp.jnlp'", "jnlp.jnlp"); + Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), lenientParserSettings); } - @Test - @KnownToFail - public void testUnquotedAttributes() throws ParseException { + @Test(expected = ParseException.class) + public void testTagNotClosedNoTagSoup() throws ParseException { + String malformedJnlp = originalJnlp.replace("</jnlp>", "<jnlp>"); + Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true, false)); + } + + @Test(expected = ParseException.class) + public void testUnquotedAttributesNoTagSoup() throws ParseException { String malformedJnlp = originalJnlp.replace("'jnlp.jnlp'", "jnlp.jnlp"); - Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); + Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()), new ParserSettings(false, true, false)); } }
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java Fri Jun 21 12:15:03 2013 +0200 @@ -58,15 +58,16 @@ private static final Locale LANG_COUNTRY_LOCALE = new Locale(LANG, COUNTRY); private static final Locale ALL_LOCALE = new Locale(LANG, COUNTRY, VARIANT); + ParserSettings defaultParser=new ParserSettings(); @Test(expected = MissingInformationException.class) public void testMissingInfoFullLocale() throws ParseException { String data = "<jnlp></jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); parser.getInfo(root); } @@ -77,11 +78,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -100,11 +101,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -130,10 +131,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); @@ -157,10 +158,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); @@ -180,10 +181,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -211,10 +212,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -242,10 +243,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -272,10 +273,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -301,10 +302,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -329,10 +330,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -356,10 +357,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -380,10 +381,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -404,10 +405,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -426,11 +427,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -449,11 +450,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -488,11 +489,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly five info descs should be found", infoDescs.size() == 5); @@ -511,11 +512,11 @@ public void testMissingInfoLangCountryLocale() throws ParseException { String data = "<jnlp></jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); parser.getInfo(root); } @@ -526,11 +527,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -549,11 +550,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -575,10 +576,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); @@ -602,10 +603,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); @@ -625,10 +626,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -656,10 +657,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -687,10 +688,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -717,10 +718,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -746,10 +747,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -774,10 +775,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -801,10 +802,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -825,10 +826,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -849,10 +850,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -871,11 +872,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -894,11 +895,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -933,11 +934,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly five info descs should be found", infoDescs.size() == 5); @@ -956,11 +957,11 @@ public void testMissingInfoLangLocale() throws ParseException { String data = "<jnlp></jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); parser.getInfo(root); } @@ -971,11 +972,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -994,11 +995,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -1016,10 +1017,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -1040,10 +1041,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); @@ -1063,10 +1064,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); @@ -1094,10 +1095,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -1125,10 +1126,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); @@ -1151,10 +1152,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); @@ -1179,10 +1180,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -1206,10 +1207,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -1230,10 +1231,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -1254,10 +1255,10 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -1276,11 +1277,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -1299,11 +1300,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = new ArrayList<InformationDesc>(); infoDescs.addAll(parser.getInfo(root)); @@ -1338,11 +1339,11 @@ + " </information>\n" + "</jnlp>\n"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false); + Parser parser = new Parser(file, null, root, defaultParser); List<InformationDesc> infoDescs = parser.getInfo(root); Assert.assertTrue("Exactly five info descs should be found", infoDescs.size() == 5); @@ -1366,12 +1367,12 @@ ">\n" + "</jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false, overwrittenCodebase); + Parser parser = new Parser(file, null, root, defaultParser, overwrittenCodebase); Assert.assertEquals("http://www.redhat.com/", parser.getCodeBase().toExternalForm()); } @@ -1385,12 +1386,12 @@ ">\n" + "</jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false, overwrittenCodebase); + Parser parser = new Parser(file, null, root, defaultParser, overwrittenCodebase); Assert.assertEquals(overwrittenCodebase.toExternalForm(), parser.getCodeBase().toExternalForm()); } @@ -1403,12 +1404,12 @@ ">\n" + "</jnlp>"; - Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()), defaultParser); Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); - Parser parser = new Parser(file, null, root, false, false, overwrittenCodebase); + Parser parser = new Parser(file, null, root, defaultParser, overwrittenCodebase); Assert.assertEquals(overwrittenCodebase.toExternalForm(), parser.getCodeBase().toExternalForm()); }
--- a/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java Fri Jun 21 12:15:03 2013 +0200 @@ -48,7 +48,8 @@ return JNLPHref; } - public JNLPFile create(URL location, Version version, boolean strict, + @Override + public JNLPFile create(URL location, Version version, ParserSettings settings, UpdatePolicy policy, URL forceCodebase) throws IOException, ParseException { JNLPHref = location; return new MockJNLPFile(); @@ -195,6 +196,8 @@ } @Test + //http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/applet/codebase_determination.html + //example 3 public void testEmbeddedJnlpWithInvalidCodebase() throws Exception { URL overwrittenCodebase = new URL("http://icedtea.classpath.org"); String relativeLocation = "/EmbeddedJnlpFile.jnlp";
--- a/tests/netx/unit/net/sourceforge/jnlp/splashscreen/parts/InformationElementTest.java Thu Jun 20 17:00:52 2013 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/splashscreen/parts/InformationElementTest.java Fri Jun 21 12:15:03 2013 +0200 @@ -43,6 +43,7 @@ import java.io.UnsupportedEncodingException; import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.ParseException; +import net.sourceforge.jnlp.ParserSettings; import org.junit.Assert; import org.junit.Test; @@ -219,6 +220,7 @@ @Test public void createFromJNLP() throws UnsupportedEncodingException, ParseException { + ParserSettings parser = new ParserSettings(); JNLPFile jnlpFile0 = null; InformationElement ie0 = InformationElement.createFromJNLP(jnlpFile0); Assert.assertNotNull(ie0); @@ -226,7 +228,7 @@ Exception ex = null; JNLPFile jnlpFile1 = null; try { - jnlpFile1 = new JNLPFile(new ByteArrayInputStream(exJnlp1.getBytes("utf-8")), true); + jnlpFile1 = new JNLPFile(new ByteArrayInputStream(exJnlp1.getBytes("utf-8")), parser); } catch (Exception eex) { ex = eex; } @@ -236,28 +238,28 @@ //title, vendor and homepage are obligatory.. not so much to test String exJnlp2 = testJnlpheader + title.toXml() + "\n" + homepage.toXml() + "\n" + vendor.toXml() + "\n" + testJnlpFooter; - JNLPFile jnlpFile2 = new JNLPFile(new ByteArrayInputStream(exJnlp2.getBytes("utf-8")), true); + JNLPFile jnlpFile2 = new JNLPFile(new ByteArrayInputStream(exJnlp2.getBytes("utf-8")), parser); InformationElement ie2 = InformationElement.createFromJNLP(jnlpFile2); Assert.assertNotNull(ie2); Assert.assertEquals(3, ie2.getHeader().size()); Assert.assertEquals(0, ie2.getDescriptions().size()); String exJnlp3 = testJnlpheader + title.toXml() + "\n" + homepage.toXml() + "\n" + vendor.toXml() + "\n" + toolTipD.toXml() + "\n" + testJnlpFooter; - JNLPFile jnlpFile3 = new JNLPFile(new ByteArrayInputStream(exJnlp3.getBytes("utf-8")), true); + JNLPFile jnlpFile3 = new JNLPFile(new ByteArrayInputStream(exJnlp3.getBytes("utf-8")), parser); InformationElement ie3 = InformationElement.createFromJNLP(jnlpFile3); Assert.assertNotNull(ie3); Assert.assertEquals(3, ie3.getHeader().size()); Assert.assertEquals(1, ie3.getDescriptions().size()); String exJnlp4 = testJnlpheader + title.toXml() + "\n" + homepage.toXml() + "\n" + vendor.toXml() + "\n" + noKindD.toXml() + "\n" + testJnlpFooter; - JNLPFile jnlpFile4 = new JNLPFile(new ByteArrayInputStream(exJnlp4.getBytes("utf-8")), true); + JNLPFile jnlpFile4 = new JNLPFile(new ByteArrayInputStream(exJnlp4.getBytes("utf-8")), parser); InformationElement ie4 = InformationElement.createFromJNLP(jnlpFile4); Assert.assertNotNull(ie4); Assert.assertEquals(3, ie4.getHeader().size()); Assert.assertEquals(1, ie4.getDescriptions().size()); String exJnlp5 = testJnlpheader + title.toXml() + "\n" + homepage.toXml() + "\n" + vendor.toXml() + "\n" + noKindD.toXml() + "\n" + toolTipD.toXml() + "\n" + testJnlpFooter; - JNLPFile jnlpFile5 = new JNLPFile(new ByteArrayInputStream(exJnlp5.getBytes("utf-8")), true); + JNLPFile jnlpFile5 = new JNLPFile(new ByteArrayInputStream(exJnlp5.getBytes("utf-8")), parser); InformationElement ie5 = InformationElement.createFromJNLP(jnlpFile5); Assert.assertNotNull(ie5); Assert.assertEquals(3, ie5.getHeader().size());