diff options
author | Leif Åstrand <leif@vaadin.com> | 2011-08-23 09:31:02 +0000 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2011-08-23 09:31:02 +0000 |
commit | b5ad3151338da797325195643c2de5f4f4829ef2 (patch) | |
tree | f8cf3d88292477d797f23acc4700d2fa0a3eee50 | |
parent | f51cb5b9b5024c68862a48d74db493067a597c0c (diff) | |
download | vaadin-framework-b5ad3151338da797325195643c2de5f4f4829ef2.tar.gz vaadin-framework-b5ad3151338da797325195643c2de5f4f4829ef2.zip |
#5488 Link: Error when trying to use a link to a file with a percent in the filename
svn changeset:20554/svn branch:6.7
4 files changed, 93 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java index 752e4c4760..f619c1c239 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java @@ -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) { diff --git a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java index 69443958e5..dd5d61ea57 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java +++ b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java @@ -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 index 0000000000..7dff317288 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/link/LinkToPercentage.html @@ -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 index 0000000000..ce8626444c --- /dev/null +++ b/tests/src/com/vaadin/tests/components/link/LinkToPercentage.java @@ -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); + } + +} |