Skip to content
Snippets Groups Projects
Commit 9d7d4f01 authored by srosse's avatar srosse
Browse files

OO-903: filter the control characters

parent bc3bd492
No related branches found
No related tags found
No related merge requests found
...@@ -152,8 +152,9 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl ...@@ -152,8 +152,9 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl
* @param value The value to set * @param value The value to set
*/ */
public void setValue(String value) { public void setValue(String value) {
if (value == null) value = ""; if (value == null) {
else { value = "";
} else {
if(!preventTrim) // OO-31 if(!preventTrim) // OO-31
value = value.trim(); value = value.trim();
...@@ -165,7 +166,8 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl ...@@ -165,7 +166,8 @@ public abstract class AbstractTextElement extends FormItemImpl implements TextEl
originalInitialised = true; originalInitialised = true;
} }
} }
this.value = value;
this.value = value.replaceAll("\\p{C}", "");
Component c = getComponent(); Component c = getComponent();
if (c != null) { if (c != null) {
// c may be null since it is only created when this formelement is added to a FormItemContainer // c may be null since it is only created when this formelement is added to a FormItemContainer
......
/**
* <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) {
//
}
}
}
...@@ -49,6 +49,7 @@ import org.junit.runners.Suite; ...@@ -49,6 +49,7 @@ import org.junit.runners.Suite;
org.olat.core.gui.components.table.TableEventTest.class, org.olat.core.gui.components.table.TableEventTest.class,
org.olat.core.gui.components.table.TableMultiSelectEventTest.class, org.olat.core.gui.components.table.TableMultiSelectEventTest.class,
org.olat.core.gui.components.table.SorterTest.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.commons.chiefcontrollers.ChiefControllerMessageEventTest.class,
org.olat.core.util.vfs.VFSManagerTest.class, org.olat.core.util.vfs.VFSManagerTest.class,
org.olat.core.util.filter.impl.XSSFilterTest.class, org.olat.core.util.filter.impl.XSSFilterTest.class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment