From 99fccc3252e034ff0f5a3c6b3b896540b8abd7a8 Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Wed, 9 Jan 2019 12:25:55 +0100 Subject: [PATCH] OO-3801: trim folder names in WebDAV provider for courses --- .../services/webdav/servlets/RequestUtil.java | 3 +- .../webdav/servlets/RequestUtilsTest.java | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/olat/core/commons/services/webdav/servlets/RequestUtil.java b/src/main/java/org/olat/core/commons/services/webdav/servlets/RequestUtil.java index 68330adbcbc..4181ee64908 100644 --- a/src/main/java/org/olat/core/commons/services/webdav/servlets/RequestUtil.java +++ b/src/main/java/org/olat/core/commons/services/webdav/servlets/RequestUtil.java @@ -502,7 +502,8 @@ public final class RequestUtil { default: sb.append(ch); } } - return Normalizer.normalize(sb, Normalizer.Form.NFC); + String normalized = Normalizer.normalize(sb, Normalizer.Form.NFC); + return normalized.trim(); } } diff --git a/src/test/java/org/olat/core/commons/services/webdav/servlets/RequestUtilsTest.java b/src/test/java/org/olat/core/commons/services/webdav/servlets/RequestUtilsTest.java index 039c6d45a60..9130366c865 100644 --- a/src/test/java/org/olat/core/commons/services/webdav/servlets/RequestUtilsTest.java +++ b/src/test/java/org/olat/core/commons/services/webdav/servlets/RequestUtilsTest.java @@ -19,8 +19,14 @@ */ package org.olat.core.commons.services.webdav.servlets; +import java.util.Arrays; +import java.util.Collection; + import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; /** * @@ -28,19 +34,30 @@ import org.junit.Test; * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com * */ +@RunWith(Parameterized.class) public class RequestUtilsTest { + @Parameters + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][] { + { "Test", "Test" }, + { "Test\u00E9\u00E4", "Test\u00E9\u00E4" }, + { "%12 ?()_//", "_12 _()___" }, + { " Test ", "Test" } + }); + } + + private String filename; + private String normalizedFilename; + + public RequestUtilsTest(String filename, String normalizedFilename) { + this.filename = filename; + this.normalizedFilename = normalizedFilename; + } + @Test public void testNormalizeFilename() { - String simpleFilename = RequestUtil.normalizeFilename("Test"); - Assert.assertEquals("Test", simpleFilename); - - String accentFilename = RequestUtil.normalizeFilename("Test\u00E9\u00E4"); - Assert.assertEquals("Test\u00E9\u00E4", accentFilename); - - String moreSpecialChars = RequestUtil.normalizeFilename("%12 ?()_//"); - Assert.assertEquals("_12 _()___", moreSpecialChars); + String correctedFilename = RequestUtil.normalizeFilename(filename); + Assert.assertEquals(normalizedFilename, correctedFilename); } - - } -- GitLab