From 39bf8185b95149ab535699966ca4f3e38a0d37ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 16 Aug 2011 12:03:58 +0000 Subject: [PATCH] #7422 Updated fix for coping with additional spaces in the input svn changeset:20416/svn branch:6.7 --- src/com/vaadin/ui/AbstractComponent.java | 17 ++++++++++++----- .../TestAbstractComponentStyleNames.java | 10 ++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index ad95b6ed58..836ea498fd 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -7,7 +7,6 @@ package com.vaadin.ui; import java.io.Serializable; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -225,8 +224,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource styles = new ArrayList(); } styles.clear(); - String[] styleParts = style.split(" "); - styles.addAll(Arrays.asList(styleParts)); + String[] styleParts = style.split(" +"); + for (String part : styleParts) { + if (part.length() > 0) { + styles.add(part); + } + } requestRepaint(); } @@ -245,8 +248,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource public void removeStyleName(String style) { if (styles != null) { - String[] styleParts = style.split(" "); - styles.removeAll(Arrays.asList(styleParts)); + String[] styleParts = style.split(" +"); + for (String part : styleParts) { + if (part.length() > 0) { + styles.remove(part); + } + } requestRepaint(); } } diff --git a/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java b/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java index 9d31029698..b1c4a8f4be 100644 --- a/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java +++ b/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java @@ -41,13 +41,19 @@ public class TestAbstractComponentStyleNames extends TestCase { assertEquals(component.getStyleName(), "style2"); } - public void testRemoveMultiple() { + public void testRemoveMultipleWithExtraSpaces() { AbstractComponent component = getComponent(); component.setStyleName("style1 style2 style3"); - component.removeStyleName("style1 style3"); + component.removeStyleName(" style1 style3 "); assertEquals(component.getStyleName(), "style2"); } + public void testSetWithExtraSpaces() { + AbstractComponent component = getComponent(); + component.setStyleName(" style1 style2 "); + assertEquals(component.getStyleName(), "style1 style2"); + } + private AbstractComponent getComponent() { return new AbstractComponent() { }; -- 2.39.5