summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2014-12-04 14:36:11 +0200
committerSauli Tähkäpää <sauli@vaadin.com>2014-12-09 12:16:16 +0200
commit3e3a1cd47da6478a0c308b42925928b9e11ef968 (patch)
tree929fa5e9a461eec3a9464b0e96bb00c60756c0b8
parentf6ff9172302d89fedd96ce3506a6e1739af5ff6c (diff)
downloadvaadin-framework-3e3a1cd47da6478a0c308b42925928b9e11ef968.tar.gz
vaadin-framework-3e3a1cd47da6478a0c308b42925928b9e11ef968.zip
Add null check to UI.setTheme. (#15326)
Change-Id: I2ab2d24ec05bb618969f59ea15d3a971f88009ca
-rw-r--r--server/src/com/vaadin/ui/UI.java12
-rw-r--r--server/tests/src/com/vaadin/ui/UIThemeEscaping.java64
2 files changed, 61 insertions, 15 deletions
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index 44948dfb6f..4bd4b67259 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -633,11 +633,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
this.embedId = embedId;
// Actual theme - used for finding CustomLayout templates
- String unescapedThemeName = request.getParameter("theme");
- if (unescapedThemeName != null) {
- // Set theme escapes the name
- setTheme(unescapedThemeName);
- }
+ setTheme(request.getParameter("theme"));
getPage().init(request);
@@ -1168,7 +1164,11 @@ public abstract class UI extends AbstractSingleComponentContainer implements
* The new theme name
*/
public void setTheme(String theme) {
- getState().theme = VaadinServlet.stripSpecialChars(theme);
+ if(theme == null) {
+ getState().theme = null;
+ } else {
+ getState().theme = VaadinServlet.stripSpecialChars(theme);
+ }
}
/**
diff --git a/server/tests/src/com/vaadin/ui/UIThemeEscaping.java b/server/tests/src/com/vaadin/ui/UIThemeEscaping.java
index ca6782952d..236f283823 100644
--- a/server/tests/src/com/vaadin/ui/UIThemeEscaping.java
+++ b/server/tests/src/com/vaadin/ui/UIThemeEscaping.java
@@ -15,29 +15,75 @@
*/
package com.vaadin.ui;
-import org.junit.Assert;
+import com.vaadin.server.VaadinRequest;
+import org.junit.Before;
import org.junit.Test;
-import com.vaadin.server.VaadinRequest;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class UIThemeEscaping {
- @Test
- public void testThemeEscaping() {
- UI ui = new UI() {
+ private UI ui;
+
+ private void initUiWithTheme(String theme) {
+ VaadinRequest request = getRequestWithTheme(theme);
+
+ ui.doInit(request, 1234, "foobar");
+ }
+
+ private VaadinRequest getRequestWithTheme(String theme) {
+ VaadinRequest request = mock(VaadinRequest.class);
+
+ when(request.getParameter("theme")).thenReturn(theme);
+
+ return request;
+ }
+
+ @Before
+ public void setup() {
+ ui = new UI() {
@Override
protected void init(VaadinRequest request) {
// Nothing to do
}
};
+ }
+ @Test
+ public void dangerousCharactersAreRemoved() {
ui.setTheme("a<å(_\"$");
- String theme = ui.getTheme();
+ assertThat(ui.getTheme(), is("aå_$"));
+ }
+
+ @Test
+ public void nullThemeIsSet() {
+ ui.setTheme("foobar");
+
+ ui.setTheme(null);
- Assert.assertEquals(
- "Dangerous characters should be removed from the theme name",
- "aå_$", theme);
+ assertThat(ui.getTheme(), is(nullValue()));
}
+ @Test
+ public void themeIsSetOnInit() {
+ ui.setTheme("foobar");
+
+ initUiWithTheme("bar");
+
+ assertThat(ui.getTheme(), is("bar"));
+ }
+
+ @Test
+ public void nullThemeIsSetOnInit() {
+ ui.setTheme("foobar");
+
+ initUiWithTheme(null);
+
+ assertThat(ui.getTheme(), is(nullValue()));
+ }
}