diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java index a2d3d843642f95dafae04f925f111eeef76d9f0f..a720658e23e2f21e361b25a704578a646e2e6ba8 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElement.java @@ -152,8 +152,9 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl * @param value The value to set */ public void setValue(String value) { - if (value == null) value = ""; - else { + if (value == null) { + value = ""; + } else { if(!preventTrim) // OO-31 value = value.trim(); @@ -165,7 +166,8 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl originalInitialised = true; } } - this.value = value; + + this.value = value.replaceAll("\\p{C}", ""); Component c = getComponent(); if (c != null) { // c may be null since it is only created when this formelement is added to a FormItemContainer diff --git a/src/test/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElementTest.java b/src/test/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElementTest.java new file mode 100644 index 0000000000000000000000000000000000000000..931875e18e96ecbc1a761c2b0a48c00d5b2794ea --- /dev/null +++ b/src/test/java/org/olat/core/gui/components/form/flexible/impl/elements/AbstractTextElementTest.java @@ -0,0 +1,85 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.gui.components.form.flexible.impl.elements; + +import junit.framework.Assert; + +import org.junit.Test; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.test.OlatTestCase; + +/** + * + * Initial date: 11.12.2013<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class AbstractTextElementTest extends OlatTestCase { + + @Test + public void filterPrintControlCharacter() { + TestTextElement element = new TestTextElement("test"); + element.setValue("Hello world"); + Assert.assertEquals("Dummy test", "Hello world", element.getValue()); + + //print control + element.setValue("Hello\u0002 world"); + Assert.assertEquals("Print \\x02 test", "Hello world", element.getValue()); + + //print control + element.setValue("Hello\u001F world"); + Assert.assertEquals("Print \\x02 like test", "Hello world", element.getValue()); + + //it's a 0 + element.setValue("Hello\u0030 world"); + Assert.assertEquals("Print \\x02 test", "Hello0 world", element.getValue()); + + //it's a u umlaut + element.setValue("Hello\u00FC world"); + Assert.assertEquals("Umlaut test", "Hello\u00FC world", element.getValue()); + + //it's a kanji + element.setValue("Hello\u30b0 world"); + Assert.assertEquals("Umlaut test", "Hello\u30b0 world", element.getValue()); + + //it's a unicode emoticons + element.setValue("Hello\u1F605 world"); + Assert.assertEquals("Umlaut test", "Hello\u1F605 world", element.getValue()); + } + + public static class TestTextElement extends AbstractTextElement { + + public TestTextElement(String name) { + super(name, name, false); + } + + @Override + protected Component getFormItemComponent() { + return null; + } + + @Override + public void evalFormRequest(UserRequest ureq) { + // + } + + } +} diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index 7235870dcb111167c92d0d9a3a765b8787b4a0da..2f9ee40f499aa9b813e3f4fba328b276b6deb15d 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -49,6 +49,7 @@ import org.junit.runners.Suite; org.olat.core.gui.components.table.TableEventTest.class, org.olat.core.gui.components.table.TableMultiSelectEventTest.class, org.olat.core.gui.components.table.SorterTest.class, + org.olat.core.gui.components.form.flexible.impl.elements.AbstractTextElementTest.class, org.olat.core.commons.chiefcontrollers.ChiefControllerMessageEventTest.class, org.olat.core.util.vfs.VFSManagerTest.class, org.olat.core.util.filter.impl.XSSFilterTest.class,