From: Maria Odea B. Ching Date: Wed, 1 May 2013 10:07:11 +0000 (+0000) Subject: [MRM-1757] remove trailing '/' in application url if present + unit test X-Git-Tag: archiva-1.4-M4~45 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1799c0c11ddd196c5c8ff9ab124cd094f1364f7f;p=archiva.git [MRM-1757] remove trailing '/' in application url if present + unit test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1477941 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java index bf0bad9e9..854da3e59 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java @@ -366,6 +366,10 @@ public class DefaultArchivaAdministrationService { try { + // fix for MRM-1757 + // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI + uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/")); + archivaAdministration.updateUiConfiguration( uiConfiguration ); } catch ( RepositoryAdminException e ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java index 9c9e18653..63c5d74cb 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java @@ -140,6 +140,35 @@ public class ArchivaAdministrationServiceTest assertEquals( url, ui.getApplicationUrl() ); } + @Test + public void uiConfigurationUpdate_ApplicationUrlHasTrailingSlash() + throws Exception { + + UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration(); + assertNotNull( ui ); + assertNull( ui.getApplicationUrl() ); + + String url = "http://foo.fr/bar/"; + ui.setApplicationUrl( url ); + + getArchivaAdministrationService().setUiConfiguration( ui ); + + ui = getArchivaAdministrationService().getUiConfiguration(); + + assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() ); + + // test if multiple '/' is trailing + url = "http://foo.fr/bar//"; + + ui.setApplicationUrl(url); + + getArchivaAdministrationService().setUiConfiguration(ui); + + ui = getArchivaAdministrationService().getUiConfiguration(); + + assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() ); + } + @Test public void getKnownContentAdminRepositoryConsumer() throws Exception