# HG changeset patch # User Jiri Vanek # Date 1412872962 -7200 # Node ID a0d25551282d8939774bf7bb27ca148f15b4de8d # Parent a54294dbc82d7bf6c44455495c721f8a2ad65ecb Empty "" codebase now behaves as "." codebase diff -r a54294dbc82d -r a0d25551282d ChangeLog --- a/ChangeLog Tue Sep 02 11:46:09 2014 -0400 +++ b/ChangeLog Thu Oct 09 18:42:42 2014 +0200 @@ -1,3 +1,15 @@ +2014-10-09 Jiri Vanek + + Empty "" codebase now behaves as "." codebase + * file netx/net/sourceforge/jnlp/Parser.java: introduced CODEBASE constant + to avoid duplicated String getAttribute split to getCleanAttribute, which + get the pure attribute, and remaining getAttribute keep adding null in case + of empty + * file netx/net/sourceforge/jnlp/security/SecurityDialogs.java: added + workaround about possible null codebase + * file tests/netx/unit/net/sourceforge/jnlp/ParserTest.java: added test for + empty codebase + 2014-09-02 Jie Kang Fixed CacheUtils clearCache method to also clear the Least Recently Used diff -r a54294dbc82d -r a0d25551282d netx/net/sourceforge/jnlp/Parser.java --- a/netx/net/sourceforge/jnlp/Parser.java Tue Sep 02 11:46:09 2014 -0400 +++ b/netx/net/sourceforge/jnlp/Parser.java Thu Oct 09 18:42:42 2014 +0200 @@ -39,6 +39,8 @@ * @version $Revision: 1.13 $ */ class Parser { + + private static String CODEBASE = "codebase"; // defines netx.jnlp.Node class if using Tiny XML or Nano XML @@ -143,7 +145,7 @@ this.spec = getVersion(root, "spec", "1.0+"); try { - this.codebase = addSlash(getURL(root, "codebase", base)); + this.codebase = addSlash(getURL(root, CODEBASE, base)); } catch (ParseException e) { //If parsing fails, continue by overriding the codebase with the one passed in } @@ -1065,10 +1067,20 @@ * @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); + //in case of null code can throw an exception later + //some bogus jnlps have codebase as "" and expect it behaving as "." + if (href != null && 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 +1266,17 @@ public String getAttribute(Node node, String name, String defaultValue) { // SAX // String result = ((Element) node).getAttribute(name); - String result = node.getAttribute(name); + String result = getCleanAttribute(node, name); + + if (result == null || result.length() == 0) { + return defaultValue; + } - if (result == null || result.length() == 0) - return defaultValue; + return result; + } + private String getCleanAttribute(Node node, String name) { + String result = node.getAttribute(name); return result; } diff -r a54294dbc82d -r a0d25551282d netx/net/sourceforge/jnlp/security/SecurityDialogs.java --- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Tue Sep 02 11:46:09 2014 -0400 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Thu Oct 09 18:42:42 2014 +0200 @@ -276,7 +276,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 a54294dbc82d -r a0d25551282d tests/netx/unit/net/sourceforge/jnlp/ParserTest.java --- a/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java Tue Sep 02 11:46:09 2014 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java Thu Oct 09 18:42:42 2014 +0200 @@ -1413,4 +1413,30 @@ Assert.assertEquals(overwrittenCodebase.toExternalForm(), parser.getCodeBase().toExternalForm()); } + + + @Test + public void testEmptyCodebase() throws Exception { + String data = "\n" + + "\n" + + ""; + + 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); + } }