changeset 50:87624fe05628

fix PR592: netx can create invalid desktop entry files 2010-11-24 Omair Majid <omajid@redhat.com> Fix PR592. * netx/net/sourceforge/jnlp/util/XDesktopEntry.java (getContentsAsReader): Sanitize information before adding to desktop file. (sanitize): New method. Ensure that there are no newlines in input.
author Omair Majid <omajid@redhat.com>
date Wed, 24 Nov 2010 13:12:52 -0500
parents 476a91d02140
children 75832973e0fa
files ChangeLog netx/net/sourceforge/jnlp/util/XDesktopEntry.java
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 24 10:55:50 2010 -0500
+++ b/ChangeLog	Wed Nov 24 13:12:52 2010 -0500
@@ -1,3 +1,10 @@
+2010-11-24  Omair Majid  <omajid@redhat.com>
+
+	Fix PR592.
+	* netx/net/sourceforge/jnlp/util/XDesktopEntry.java
+	(getContentsAsReader): Sanitize information before adding to desktop file.
+	(sanitize): New method. Ensure that there are no newlines in input.
+
 2010-11-24  Omair Majid  <omajid@redhat.com>
 
 	* netx/net/sourceforge/jnlp/resources/Messages.properties: Add
--- a/netx/net/sourceforge/jnlp/util/XDesktopEntry.java	Wed Nov 24 10:55:50 2010 -0500
+++ b/netx/net/sourceforge/jnlp/util/XDesktopEntry.java	Wed Nov 24 13:12:52 2010 -0500
@@ -80,9 +80,9 @@
 
         String fileContents = "[Desktop Entry]\n";
         fileContents += "Version=1.0\n";
-        fileContents += "Name=" + file.getTitle() + "\n";
+        fileContents += "Name=" + sanitize(file.getTitle()) + "\n";
         fileContents += "GenericName=Java Web Start Application\n";
-        fileContents += "Comment=" + file.getInformation().getDescription() + "\n";
+        fileContents += "Comment=" + sanitize(file.getInformation().getDescription()) + "\n";
         fileContents += "Type=Application\n";
         if (iconLocation != null) {
             fileContents += "Icon=" + iconLocation + "\n";
@@ -91,7 +91,7 @@
 
         }
         if (file.getInformation().getVendor() != null) {
-            fileContents += "Vendor=" + file.getInformation().getVendor() + "\n";
+            fileContents += "Vendor=" + sanitize(file.getInformation().getVendor()) + "\n";
         }
 
         //Shortcut executes the jnlp from cache and system preferred java..
@@ -102,6 +102,22 @@
     }
 
     /**
+     * Sanitizes a string so that it can be used safely in a key=value pair in a
+     * desktop entry file.
+     *
+     * @param input a String to sanitize
+     * @return a string safe to use as either the key or the value in the
+     * key=value pair in a desktop entry file
+     */
+    private static String sanitize(String input) {
+        if (input == null) {
+            return "";
+        }
+        /* key=value pairs must be a single line */
+        return input.split("\n")[0];
+    }
+
+    /**
      * Get the size of the icon (in pixels) for the desktop shortcut
      */
     public int getIconSize() {