Bug 435720 - Trim whitespace from non-proxy hosts in DefaultProxySelector

Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/fbf380ce
Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/fbf380ce
Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/fbf380ce

Branch: refs/heads/master
Commit: fbf380ce48b6b10a9f851332c1d37a4abf4a01d7
Parents: caf41ec
Author: Benjamin Bentmann <bentm...@sonatype.com>
Authored: Sun May 25 23:06:47 2014 +0200
Committer: Benjamin Bentmann <bentm...@sonatype.com>
Committed: Sun May 25 23:06:47 2014 +0200

----------------------------------------------------------------------
 .../aether/util/repository/DefaultProxySelector.java   |  8 ++++----
 .../util/repository/DefaultProxySelectorTest.java      | 13 +++++++++----
 2 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-aether/blob/fbf380ce/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
----------------------------------------------------------------------
diff --git 
a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
 
b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
index a47b5ac..0bccf8a 100644
--- 
a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
+++ 
b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
@@ -38,9 +38,9 @@ public final class DefaultProxySelector
      * 
      * @param proxy The proxy definition to add, must not be {@code null}.
      * @param nonProxyHosts The list of (case-insensitive) host names to 
exclude from proxying, may be {@code null}. The
-     *            syntax of this list matches that of the property 
"http.nonProxyHosts" from the JRE, i.e. the asterisk
-     *            character ('*') serves as a wildcard for pattern matching. 
Multiple non-proxy hosts are separated by
-     *            the pipe character ('|') but note that surrounding 
whitespace is not trimmed from the entries.
+     *            syntax of this list resembles that of the property 
"http.nonProxyHosts" from the JRE, i.e. the
+     *            asterisk character ('*') serves as a wildcard for pattern 
matching. Multiple entries are separated by
+     *            the pipe character ('|') and surrounding whitespace is 
trimmed.
      * @return This proxy selector for chaining, never {@code null}.
      */
     public DefaultProxySelector add( Proxy proxy, String nonProxyHosts )
@@ -139,7 +139,7 @@ public final class DefaultProxySelector
             List<String> hosts = null;
             if ( nonProxyHosts != null )
             {
-                hosts = Arrays.asList( nonProxyHosts.split( "\\|" ) );
+                hosts = Arrays.asList( nonProxyHosts.trim().split( 
"\\s*\\|\\s*" ) );
             }
             return hosts;
         }

http://git-wip-us.apache.org/repos/asf/maven-aether/blob/fbf380ce/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
----------------------------------------------------------------------
diff --git 
a/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
 
b/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
index a8cc141..6ae5f2b 100644
--- 
a/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
+++ 
b/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
@@ -64,11 +64,16 @@ public class DefaultProxySelectorTest
         assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org|host2" ) 
);
 
         assertFalse( isNonProxyHost( "", "||host||" ) );
+    }
 
-        // controversial (no trimming) but consistent with JRE's handling of 
http.nonProxyHosts
-        assertFalse( isNonProxyHost( "eclipse.org", "host1| eclipse.org 
|host2" ) );
-        assertFalse( isNonProxyHost( "eclipse.org", "host1|eclipse.org " ) );
-        assertFalse( isNonProxyHost( "eclipse.org", " eclipse.org|host2" ) );
+    @Test
+    public void testIsNonProxyHost_Trimming()
+    {
+        assertFalse( isNonProxyHost( "", " " ) );
+        assertTrue( isNonProxyHost( "eclipse.org", " eclipse.org " ) );
+        assertTrue( isNonProxyHost( "eclipse.org", "host1| eclipse.org |host2" 
) );
+        assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org " ) );
+        assertTrue( isNonProxyHost( "eclipse.org", " eclipse.org|host2" ) );
     }
 
     @Test

Reply via email to