]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1757] remove trailing '/' in application url if present + unit test
authorMaria Odea B. Ching <oching@apache.org>
Wed, 1 May 2013 10:07:11 +0000 (10:07 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Wed, 1 May 2013 10:07:11 +0000 (10:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1477941 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java

index bf0bad9e98b9166d5c7aac1c4eef36a8d7776049..854da3e59559ba14c91cd361c37a1fd0ca8abde3 100644 (file)
@@ -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 )
index 9c9e18653291fa6151c727c1aefec14602ad9cd5..63c5d74cb3943ac97f4b63986a733673b31325d2 100644 (file)
@@ -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