You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/07/08 19:20:07 UTC

[maven] branch MNG-6703 created (now 683a5f5)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MNG-6703
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at 683a5f5  [MNG-6703] Adopt RFC 3968 behaviour

This branch includes the following new commits:

     new 11e1bcd  [MNG-6535] Improve test coverage of UrlNormalizer.
     new 96c005a  [MNG-6535] Switch behaviour on relative URIs to match Path.normalize
     new 683a5f5  [MNG-6703] Adopt RFC 3968 behaviour

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 03/03: [MNG-6703] Adopt RFC 3968 behaviour

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-6703
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 683a5f54f20ab02442e8e0ad2f949814900adeeb
Author: Joseph Walton <jo...@kafsemo.org>
AuthorDate: Mon Jul 8 23:05:05 2019 +1000

    [MNG-6703] Adopt RFC 3968 behaviour
    
    * Adopt RFC 3968's behaviour for traversal past the root
    * Add a test that this isn't applied to relative URI references
---
 .../java/org/apache/maven/model/path/DefaultUrlNormalizer.java |  9 +++++++--
 .../org/apache/maven/model/path/DefaultUrlNormalizerTest.java  | 10 ++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
index 1260367..af445a4 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
@@ -43,10 +43,15 @@ public class DefaultUrlNormalizer
             while ( true )
             {
                 int idx = result.indexOf( "/../" );
-                if ( idx <= 0 )
+                if ( idx < 0 )
                 {
                     break;
                 }
+                else if ( idx == 0 )
+                {
+                    result = result.substring( 3 );
+                    continue;
+                }
                 int parent = idx - 1;
                 while ( parent >= 0 && result.charAt( parent ) == '/' )
                 {
@@ -55,7 +60,7 @@ public class DefaultUrlNormalizer
                 parent = result.lastIndexOf( '/', parent );
                 if ( parent < 0 )
                 {
-                    result = result.substring( idx + 4);
+                    result = result.substring( idx + 4 );
                 }
                 else
                 {
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
index d0c6343..095ff62 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
@@ -71,9 +71,9 @@ public class DefaultUrlNormalizerTest
     }
 
     @Test
-    public void relativeUriReferenceLeftUnaffectedWithNoParentDirectoryToAscendTo()
+    public void absolutePathTraversalPastRootIsOmitted()
     {
-        assertEquals( "/../", normalize("/../" ) );
+        assertEquals( "/", normalize("/../" ) );
     }
 
     @Test
@@ -81,4 +81,10 @@ public class DefaultUrlNormalizerTest
     {
         assertEquals( "", normalize( "a/../" ) );
     }
+
+    @Test
+    public void leadingParentDirectoryNotRemovedFromRelativeUriReference()
+    {
+        assertEquals( "../", normalize( "../" ) );
+    }
 }


[maven] 02/03: [MNG-6535] Switch behaviour on relative URIs to match Path.normalize

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-6703
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 96c005acaf77d1ce0c59251394e7d125c3fa35de
Author: Joseph Walton <jo...@kafsemo.org>
AuthorDate: Sun Jul 7 14:42:20 2019 +1000

    [MNG-6535] Switch behaviour on relative URIs to match Path.normalize
    
    This method could be passed relative URIs, so improve handling rather
    than doubling down on the existing behaviour. Normalize relative URIs
    to remove redundant '../'.
    
    Also switch to JUnit annotations and drop some boilerplate.
---
 .../maven/model/path/DefaultUrlNormalizer.java     |  7 ++--
 .../maven/model/path/DefaultUrlNormalizerTest.java | 41 ++++++++++------------
 2 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
index 9b9216d..1260367 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
@@ -55,9 +55,12 @@ public class DefaultUrlNormalizer
                 parent = result.lastIndexOf( '/', parent );
                 if ( parent < 0 )
                 {
-                    break;
+                    result = result.substring( idx + 4);
+                }
+                else
+                {
+                    result = result.substring( 0, parent ) + result.substring( idx + 3 );
                 }
-                result = result.substring( 0, parent ) + result.substring( idx + 3 );
             }
         }
 
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
index ac9489f..d0c6343 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
@@ -19,45 +19,31 @@ package org.apache.maven.model.path;
  * under the License.
  */
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
 
 /**
  * @author Benjamin Bentmann
  */
 public class DefaultUrlNormalizerTest
-    extends TestCase
 {
 
-    private UrlNormalizer normalizer;
-
-    @Override
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        normalizer = new DefaultUrlNormalizer();
-    }
-
-    @Override
-    protected void tearDown()
-        throws Exception
-    {
-        normalizer = null;
-
-        super.tearDown();
-    }
+    private UrlNormalizer normalizer = new DefaultUrlNormalizer();
 
     private String normalize( String url )
     {
         return normalizer.normalize( url );
     }
 
+    @Test
     public void testNullSafe()
     {
         assertNull( normalize( null ) );
     }
 
+    @Test
     public void testTrailingSlash()
     {
         assertEquals( "", normalize( "" ) );
@@ -65,6 +51,7 @@ public class DefaultUrlNormalizerTest
         assertEquals( "http://server.org/dir/", normalize( "http://server.org/dir/" ) );
     }
 
+    @Test
     public void testRemovalOfParentRefs()
     {
         assertEquals( "http://server.org/child", normalize( "http://server.org/parent/../child" ) );
@@ -74,6 +61,7 @@ public class DefaultUrlNormalizerTest
         assertEquals( "http://server.org/child", normalize( "http://server.org/parent//../child" ) );
     }
 
+    @Test
     public void testPreservationOfDoubleSlashes()
     {
         assertEquals( "scm:hg:ssh://localhost//home/user", normalize( "scm:hg:ssh://localhost//home/user" ) );
@@ -82,8 +70,15 @@ public class DefaultUrlNormalizerTest
                       normalize( "[fetch=]http://server.org/[push=]ssh://server.org/" ) );
     }
 
-    public void testNormalizeInputWithNoParentDirectoriesToAscendTo()
+    @Test
+    public void relativeUriReferenceLeftUnaffectedWithNoParentDirectoryToAscendTo()
+    {
+        assertEquals( "/../", normalize("/../" ) );
+    }
+
+    @Test
+    public void parentDirectoryRemovedFromRelativeUriReference()
     {
-        assertEquals("a/../", normalize("a/../"));
+        assertEquals( "", normalize( "a/../" ) );
     }
 }


[maven] 01/03: [MNG-6535] Improve test coverage of UrlNormalizer.

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-6703
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 11e1bcdf644cc0c3a17d33cfb44b0d82c6214ed1
Author: Joseph Walton <jo...@kafsemo.org>
AuthorDate: Mon May 20 22:17:24 2019 +1000

    [MNG-6535] Improve test coverage of UrlNormalizer.
    
    Refine the original PR to the test that improves coverage;
    give it a clearer description of its behaviour.
---
 .../java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java    | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
index 88fdc9c..ac9489f 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
@@ -82,4 +82,8 @@ public class DefaultUrlNormalizerTest
                       normalize( "[fetch=]http://server.org/[push=]ssh://server.org/" ) );
     }
 
+    public void testNormalizeInputWithNoParentDirectoriesToAscendTo()
+    {
+        assertEquals("a/../", normalize("a/../"));
+    }
 }