diff -r d8e057783109 netx/net/sourceforge/jnlp/Parser.java --- a/netx/net/sourceforge/jnlp/Parser.java Mon Sep 15 14:09:30 2014 -0400 +++ b/netx/net/sourceforge/jnlp/Parser.java Tue Sep 16 15:25:44 2014 +0200 @@ -1065,10 +1065,21 @@ * @throws ParseException if the JNLP file is invalid */ public URL getURL(Node node, String name, URL base) throws ParseException { - String href = getAttribute(node, name, null); - if (href == null) + String href = null; + if ("codebase".equals(name)) { + href = getCleanAttribute(node, name); + if (href != null) {// so that code can throw an exceptionlater + //some bogus jnlps have codebase as "" and expect it behaving as "." + if (href.trim().isEmpty()) { + href = "."; + } + } + } else { + href = getAttribute(node, name, null); + } + if (href == null) { return null; // so that code can throw an exception if attribute was required - + } try { if (base == null) return new URL(href); @@ -1254,11 +1265,17 @@ public String getAttribute(Node node, String name, String defaultValue) { // SAX // String result = ((Element) node).getAttribute(name); + String result = getCleanAttribute(node, name); + + if (result == null || result.length() == 0) { + return defaultValue; + } + + return result; + } + + public String getCleanAttribute(Node node, String name) { String result = node.getAttribute(name); - - if (result == null || result.length() == 0) - return defaultValue; - return result; } diff -r d8e057783109 netx/net/sourceforge/jnlp/security/SecurityDialogs.java --- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Mon Sep 15 14:09:30 2014 -0400 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Tue Sep 16 15:25:44 2014 +0200 @@ -44,6 +44,8 @@ import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Arrays; +import java.util.Comparator; import java.util.Set; import java.util.concurrent.Semaphore; @@ -285,7 +287,13 @@ SecurityDialogMessage message = new SecurityDialogMessage(); message.dialogType = DialogType.MISSING_ALACA; - message.extras = new Object[]{title, codeBase.toString(), UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; + String urlToShow = "unknown url"; + if (codeBase != null) { + urlToShow = codeBase.toString(); + } else { + OutputController.getLogger().log("Warning, null codebase wants to show in ALACA!"); + } + message.extras = new Object[]{title, urlToShow, UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; Object selectedValue = getUserResponse(message); return getIntegerResponseAsBoolean(selectedValue); } diff -r d8e057783109 tests/netx/unit/net/sourceforge/jnlp/ParserTest.java --- a/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java Mon Sep 15 14:09:30 2014 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java Tue Sep 16 15:25:44 2014 +0200 @@ -1413,4 +1413,30 @@ Assert.assertEquals(overwrittenCodebase.toExternalForm(), parser.getCodeBase().toExternalForm()); } + + + @Test + public void testEmptyCodebase() throws Exception { + String data = "<?xml version=\"1.0\"?>\n" + + "<jnlp spec=\"1.5+\"\n" + + "codebase=\"\" aaa=\"\" " + + ">\n" + + "</jnlp>"; + + 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, defaultParser, null); + ParseException eex = null; + //non codebase element is unaffected + URL u = parser.getURL(root, "aaa", null); + Assert.assertEquals(null, u); + try { + parser.getURL(root, "codebase", null); + } catch (ParseException ex) { + eex = ex; + } + Assert.assertEquals(true, eex != null); + Assert.assertEquals(true, eex instanceof ParseException); + } }