]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5488 Link: Error when trying to use a link to a file with a percent in the filename
authorLeif Åstrand <leif@vaadin.com>
Tue, 23 Aug 2011 09:31:02 +0000 (09:31 +0000)
committerLeif Åstrand <leif@vaadin.com>
Tue, 23 Aug 2011 09:31:02 +0000 (09:31 +0000)
svn changeset:20554/svn branch:6.7

src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java
src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java
tests/src/com/vaadin/tests/components/link/LinkToPercentage.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/link/LinkToPercentage.java [new file with mode: 0644]

index 752e4c4760a25c0a2aa483d6943e9affb45bfc5a..f619c1c2393cc9eb7eea4014b57c9e1d426ef3a7 100644 (file)
@@ -6,7 +6,9 @@ package com.vaadin.terminal.gwt.server;
 import java.io.PrintWriter;
 import java.io.Serializable;
 import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -173,11 +175,21 @@ public abstract class AbstractWebApplicationContext implements
         if (filename == null) {
             return "app://APP/" + mapKey + "/";
         } else {
-            return "app://APP/" + mapKey + "/" + filename;
+            return "app://APP/" + mapKey + "/" + urlEncode(filename);
         }
 
     }
 
+    static String urlEncode(String filename) {
+        try {
+            return URLEncoder.encode(filename, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(
+                    "UTF-8 charset not available (\"this should never happen\")",
+                    e);
+        }
+    }
+
     public boolean isApplicationResourceURL(URL context, String relativeUri) {
         // If the relative uri is null, we are ready
         if (relativeUri == null) {
index 69443958e5a14fd008441e6397de8e95e57aff70..dd5d61ea57050e7c809c49de01149e860d9d4533 100644 (file)
@@ -259,7 +259,8 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext {
             if (filename == null) {
                 resourceURL.setResourceID("APP/" + mapKey + "/");
             } else {
-                resourceURL.setResourceID("APP/" + mapKey + "/" + filename);
+                resourceURL.setResourceID("APP/" + mapKey + "/"
+                        + urlEncode(filename));
             }
             return resourceURL.toString();
         } else {
diff --git a/tests/src/com/vaadin/tests/components/link/LinkToPercentage.html b/tests/src/com/vaadin/tests/components/link/LinkToPercentage.html
new file mode 100644 (file)
index 0000000..7dff317
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>LinkToPercentage</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">LinkToPercentage</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.link.LinkToPercentage?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertAttribute</td>
+       <td>vaadin=runcomvaadintestscomponentslinkLinkToPercentage::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLink[0]/domChild[0]@href</td>
+       <td>*/run/com.vaadin.tests.components.link.LinkToPercentage/APP/1/110%25+Vaadin</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/link/LinkToPercentage.java b/tests/src/com/vaadin/tests/components/link/LinkToPercentage.java
new file mode 100644 (file)
index 0000000..ce86264
--- /dev/null
@@ -0,0 +1,51 @@
+package com.vaadin.tests.components.link;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.vaadin.terminal.ApplicationResource;
+import com.vaadin.terminal.StreamResource;
+import com.vaadin.terminal.StreamResource.StreamSource;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Link;
+
+public class LinkToPercentage extends TestBase {
+
+    @Override
+    protected void setup() {
+        String filename = "110% Vaadin";
+        ApplicationResource resource = new StreamResource(new StreamSource() {
+            public InputStream getStream() {
+                return new InputStream() {
+                    boolean first = true;
+
+                    @Override
+                    public int read() throws IOException {
+                        if (first) {
+                            first = false;
+                            return 'a';
+                        } else {
+                            return -1;
+                        }
+                    }
+                };
+            }
+        }, filename, this);
+        addResource(resource);
+
+        Link link = new Link("The link", resource);
+
+        addComponent(link);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Tests using links with percentage signs in the address";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return Integer.valueOf(5488);
+    }
+
+}