maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r368363 - in /maven/scm/trunk/maven-scm-api/src: main/java/org/apache/maven/scm/manager/ test/java/org/apache/maven/scm/manager/
Date Thu, 12 Jan 2006 13:25:57 GMT
Author: evenisse
Date: Thu Jan 12 05:25:13 2006
New Revision: 368363

URL: http://svn.apache.org/viewcvs?rev=368363&view=rev
Log:
Clean scm url when it contains some double dot like "../"
PR: SCM-101

Added:
    maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/
    maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java
  (with props)
    maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java
  (with props)
Modified:
    maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java

Modified: maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java?rev=368363&r1=368362&r2=368363&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java
(original)
+++ maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java
Thu Jan 12 05:25:13 2006
@@ -131,13 +131,64 @@
 
         ScmProvider provider = getProviderByType( providerType );
 
-        String scmSpecificUrl = scmUrl.substring( providerType.length() + 5 );
+        String scmSpecificUrl = cleanScmUrl( scmUrl.substring( providerType.length() + 5
) );
 
         ScmProviderRepository providerRepository = provider.makeProviderScmRepository( scmSpecificUrl,
delimiter );
 
         return new ScmRepository( providerType, providerRepository );
     }
 
+    protected String cleanScmUrl( String scmUrl )
+    {
+        if ( scmUrl == null )
+        {
+            throw new NullPointerException( "The scm url cannot be null." );
+        }
+
+        String pathSeparator = "";
+
+        int indexOfDoubleDot = -1;
+
+        // Clean Unix path
+        if ( scmUrl.indexOf( "../" ) > 1 )
+        {
+            pathSeparator = "/";
+
+            indexOfDoubleDot = scmUrl.indexOf( "../" );
+        }
+
+        // Clean windows path
+        if ( scmUrl.indexOf( "..\\" ) > 1 )
+        {
+            pathSeparator = "\\";
+
+            indexOfDoubleDot = scmUrl.indexOf( "..\\" );
+        }
+
+        if ( indexOfDoubleDot > 1 )
+        {
+            int startOfTextToRemove = scmUrl.substring( 0, indexOfDoubleDot - 1 ).lastIndexOf(
pathSeparator );
+
+            String beginUrl = "";
+            if ( startOfTextToRemove >= 0 )
+            {
+                beginUrl = scmUrl.substring( 0, startOfTextToRemove );
+            }
+
+            String endUrl = scmUrl.substring( indexOfDoubleDot + 3 );
+
+            scmUrl = beginUrl + pathSeparator + endUrl;
+            
+            // Check if we have other double dot
+            if ( scmUrl.indexOf( "../" ) > 1 || scmUrl.indexOf( "..\\" ) > 1 )
+            {
+                scmUrl = cleanScmUrl( scmUrl );
+            }
+        }
+
+        return scmUrl;
+    }
+
     public ScmRepository makeProviderScmRepository( String providerType, File path )
         throws ScmRepositoryException, UnknownRepositoryStructure, NoSuchScmProviderException
     {
@@ -204,7 +255,7 @@
             return messages;
         }
 
-        String scmSpecificUrl = scmUrl.substring( providerType.length() + 5 );
+        String scmSpecificUrl = cleanScmUrl( scmUrl.substring( providerType.length() + 5
) );
 
         List providerMessages = provider.validateScmUrl( scmSpecificUrl, delimiter );
 

Added: maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java?rev=368363&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java
(added)
+++ maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java
Thu Jan 12 05:25:13 2006
@@ -0,0 +1,33 @@
+package org.apache.maven.scm.manager;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.scm.log.DefaultLog;
+import org.apache.maven.scm.log.ScmLogger;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class BasicScmManager
+    extends AbstractScmManager
+{
+    protected ScmLogger getScmLogger()
+    {
+        return new DefaultLog();
+    }
+}
\ No newline at end of file

Propchange: maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/BasicScmManager.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java?rev=368363&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java
(added)
+++ maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java
Thu Jan 12 05:25:13 2006
@@ -0,0 +1,46 @@
+package org.apache.maven.scm.manager;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class ScmManagerTest
+    extends TestCase
+{
+    public void testCleanScmUrl()
+        throws Exception
+    {
+        BasicScmManager manager = new BasicScmManager();
+
+        assertEquals( "https://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-api",
+                      manager.cleanScmUrl( "https://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-api"
) );
+        assertEquals( "https://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-manager",
+                      manager.cleanScmUrl( "https://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-api/../maven-scm-manager"
) );
+        assertEquals( "https://svn.apache.org/repos/asf/maven/scm/trunk/",
+                      manager.cleanScmUrl( "https://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-api/../"
) );
+        assertEquals( "d:\\myrepo\\mydir",
+                      manager.cleanScmUrl( "d:\\myrepo\\mydir" ) );
+        assertEquals( "d:\\myrepo\\mydir2",
+                      manager.cleanScmUrl( "d:\\myrepo\\mydir\\..\\mydir2" ) );
+        assertEquals( "//depot/repos/...", manager.cleanScmUrl( "//depot/repos/..." ) );
+        assertEquals( "//depot/repo2/...", manager.cleanScmUrl( "//depot/repos/../repo2/..."
) );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-api/src/test/java/org/apache/maven/scm/manager/ScmManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message