Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 079059E10 for ; Tue, 14 Feb 2012 16:12:27 +0000 (UTC) Received: (qmail 46175 invoked by uid 500); 14 Feb 2012 16:12:27 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 46137 invoked by uid 500); 14 Feb 2012 16:12:26 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 46130 invoked by uid 99); 14 Feb 2012 16:12:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2012 16:12:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2012 16:12:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6A8272388A6E for ; Tue, 14 Feb 2012 16:12:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1244105 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/utils/URIUtils.java test/java/org/apache/http/client/utils/TestURIUtils.java Date: Tue, 14 Feb 2012 16:12:03 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120214161203.6A8272388A6E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Tue Feb 14 16:12:02 2012 New Revision: 1244105 URL: http://svn.apache.org/viewvc?rev=1244105&view=rev Log: HTTPCLIENT-1166: more tolerant parsing logic for malformed uris with invalid authority part Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java?rev=1244105&r1=1244104&r2=1244105&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java Tue Feb 14 16:12:02 2012 @@ -306,9 +306,18 @@ public class URIUtils { if (host != null) { int colon = host.indexOf(':'); if (colon >= 0) { - if (colon + 1 < host.length()) { + int pos = colon + 1; + int len = 0; + for (int i = pos; i < host.length(); i++) { + if (Character.isDigit(host.charAt(i))) { + len++; + } else { + break; + } + } + if (len > 0) { try { - port = Integer.parseInt(host.substring(colon + 1)); + port = Integer.parseInt(host.substring(pos, pos + len)); } catch (NumberFormatException ex) { } } Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java?rev=1244105&r1=1244104&r2=1244105&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java Tue Feb 14 16:12:02 2012 @@ -341,9 +341,9 @@ public class TestURIUtils { URIUtils.extractHost(new URI("http://local_host:8/abcd"))); // URI seems to OK with missing port number - Assert.assertEquals(new HttpHost("localhost"),URIUtils.extractHost( + Assert.assertEquals(new HttpHost("localhost",-1),URIUtils.extractHost( new URI("http://localhost:/abcd"))); - Assert.assertEquals(new HttpHost("local_host"),URIUtils.extractHost( + Assert.assertEquals(new HttpHost("local_host",-1),URIUtils.extractHost( new URI("http://local_host:/abcd"))); Assert.assertEquals(new HttpHost("localhost",8080), @@ -361,8 +361,10 @@ public class TestURIUtils { Assert.assertEquals(new HttpHost("localhost",8080), URIUtils.extractHost(new URI("http://localhost:8080/;sessionid=stuff/abcd"))); - Assert.assertEquals(new HttpHost("localhost",-1), + Assert.assertEquals(new HttpHost("localhost",8080), URIUtils.extractHost(new URI("http://localhost:8080;sessionid=stuff/abcd"))); + Assert.assertEquals(new HttpHost("localhost",-1), + URIUtils.extractHost(new URI("http://localhost:;sessionid=stuff/abcd"))); } }