Skip to content
Snippets Groups Projects
Commit 5045d047 authored by srosse's avatar srosse
Browse files

OO-553: improve "StringHelper.transformDisplayNameToFileSystemName" to remove...

OO-553: improve "StringHelper.transformDisplayNameToFileSystemName" to remove more special characters and all non-ascii characters in general
parent 5b9f893a
No related branches found
No related tags found
No related merge requests found
......@@ -324,10 +324,10 @@ public class StringHelper {
* @return transformed string
*/
public static String transformDisplayNameToFileSystemName(String s){
s = s.replace('?', '_');
s = s.replace('/', '_');
s = s.replace(' ', '_');
return s;
//replace some separator with an underscore
s = s.replace('?', '_').replace('\\', '_').replace('/', '_').replace(' ', '_');
//remove all non-ascii characters
return FileUtils.normalizeFilename(s);
}
public static boolean isLong(String string) {
......
......@@ -22,9 +22,8 @@ package org.olat.core.util;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Description:<br>
......@@ -34,10 +33,8 @@ import org.junit.runners.JUnit4;
* Initial Date: 13.07.2010 <br>
* @author gnaegi
*/
@RunWith(JUnit4.class)
public class StringHelperTest {
@Test
public void testContainsNonWhitespace() {
// positive tests
......@@ -53,4 +50,12 @@ public class StringHelperTest {
assertFalse(StringHelper.containsNonWhitespace(" "));
assertFalse(StringHelper.containsNonWhitespace(" \t \r"));
}
@Test
public void transformDisplayNameToFileSystemName() {
Assert.assertEquals("Webclass_Energie_2004_2005", StringHelper.transformDisplayNameToFileSystemName("Webclass Energie 2004/2005"));
Assert.assertEquals("Webclass_Energie_2004_2005", StringHelper.transformDisplayNameToFileSystemName("Webclass Energie 2004\\2005"));
Assert.assertEquals("Webclass_Energie_20042005", StringHelper.transformDisplayNameToFileSystemName("Webclass Energie 2004:2005"));
Assert.assertEquals("Webclaess", StringHelper.transformDisplayNameToFileSystemName("Webcl\u00E4ss"));
}
}
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