Skip to content

Commit

Permalink
Support HTTPS, FTP, and FTPS resource URLs in Declarative (#17267)
Browse files Browse the repository at this point in the history
Manually picked to 7.4 from commit b96861c in master, also added a test.

Change-Id: I415f7409084ea0abd8b22ba3892743e11d503c27
  • Loading branch information
jdahlstrom committed Mar 30, 2015
1 parent 043dca0 commit 73c9c8b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class DesignResourceConverter implements Converter<String, Resource> {
public Resource convertToModel(String value,
Class<? extends Resource> targetType, Locale locale)
throws Converter.ConversionException {
if (value.startsWith("http://")) {
if (value.startsWith("http://") || value.startsWith("https://")
|| value.startsWith("ftp://") || value.startsWith("ftps://")) {
return new ExternalResource(value);
} else if (value.startsWith("theme://")) {
return new ThemeResource(value.substring(8));
Expand Down
19 changes: 19 additions & 0 deletions server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ public void testTimeZone() {
assertEquals(zone, result);
}

@Test
public void testExternalResource() {
String url = "://example.com/my%20icon.png?a=b";

for (String scheme : new String[] { "http", "https", "ftp", "ftps" }) {
Resource resource = formatter.parse(scheme + url, Resource.class);

assertTrue(scheme + " url should be parsed as ExternalResource",
resource instanceof ExternalResource);
assertEquals("parsed ExternalResource", scheme + url,
((ExternalResource) resource).getURL());

String formatted = formatter.format(new ExternalResource(scheme
+ url));

assertEquals("formatted ExternalResource", scheme + url, formatted);
}
}

/**
* A static method to allow comparison two different actions.
*
Expand Down

0 comments on commit 73c9c8b

Please sign in to comment.