From b5ad3151338da797325195643c2de5f4f4829ef2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 23 Aug 2011 09:31:02 +0000 Subject: [PATCH] #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 --- .../server/AbstractWebApplicationContext.java | 14 ++++- .../server/PortletApplicationContext2.java | 3 +- .../components/link/LinkToPercentage.html | 27 ++++++++++ .../components/link/LinkToPercentage.java | 51 +++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/link/LinkToPercentage.html create mode 100644 tests/src/com/vaadin/tests/components/link/LinkToPercentage.java 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 @@ + + + + + + +LinkToPercentage + + + + + + + + + + + + + + + + + +
LinkToPercentage
open/run/com.vaadin.tests.components.link.LinkToPercentage?restartApplication
assertAttributevaadin=runcomvaadintestscomponentslinkLinkToPercentage::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLink[0]/domChild[0]@href*/run/com.vaadin.tests.components.link.LinkToPercentage/APP/1/110%25+Vaadin
+ + 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); + } + +} -- 2.39.5