From 9cc7c1acecb5ce7af867718f0d1933b3bdf3c3f1 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 28 Nov 2013 08:57:04 +0000 Subject: [PATCH] HTTPCLIENT-1440: 'file' scheme in redirect location URI causes NPE. Contributed by James Leigh git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1546315 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 3 +++ .../org/apache/http/client/utils/URIUtils.java | 3 ++- .../org/apache/http/client/utils/TestURIUtils.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 30d577d9a..706677632 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes since 4.3.1 ------------------- +* [HTTPCLIENT-1440] 'file' scheme in redirect location URI causes NPE. + Contributed by James Leigh + * [HTTPCLIENT-1437] Made Executor#execute thread safe. Contributed by Oleg Kalnichevski diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java index 6b1077ace..131f20d7a 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java @@ -259,7 +259,8 @@ public class URIUtils { * @return the URI without dot segments */ private static URI normalizeSyntax(final URI uri) { - if (uri.isOpaque()) { + if (uri.isOpaque() || uri.getAuthority() == null) { + // opaque and file: URIs return uri; } Args.check(uri.isAbsolute(), "Base URI must be absolute"); diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java index 67919af22..6050061a6 100644 --- a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java +++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java @@ -173,6 +173,20 @@ public class TestURIUtils { "http://s/mid/content=5/../6").toString()); } + @Test + public void testResolveOpaque() { + Assert.assertEquals("example://a/b/c/%7Bfoo%7D", URIUtils.resolve(this.baseURI, "eXAMPLE://a/./b/../b/%63/%7bfoo%7d").toString()); + Assert.assertEquals("file://localhost/etc/fstab", URIUtils.resolve(this.baseURI, "file://localhost/etc/fstab").toString()); + Assert.assertEquals("file:///etc/fstab", URIUtils.resolve(this.baseURI, "file:///etc/fstab").toString()); + Assert.assertEquals("file://localhost/c:/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file://localhost/c:/WINDOWS/clock.avi").toString()); + Assert.assertEquals("file:///c:/WINDOWS/clock.avi", URIUtils.resolve(this.baseURI, "file:///c:/WINDOWS/clock.avi").toString()); + Assert.assertEquals("file://hostname/path/to/the%20file.txt", URIUtils.resolve(this.baseURI, "file://hostname/path/to/the%20file.txt").toString()); + Assert.assertEquals("file:///c:/path/to/the%20file.txt", URIUtils.resolve(this.baseURI, "file:///c:/path/to/the%20file.txt").toString()); + Assert.assertEquals("urn:issn:1535-3613", URIUtils.resolve(this.baseURI, "urn:issn:1535-3613").toString()); + Assert.assertEquals("mailto:user@example.com", URIUtils.resolve(this.baseURI, "mailto:user@example.com").toString()); + Assert.assertEquals("ftp://example.org/resource.txt", URIUtils.resolve(this.baseURI, "ftp://example.org/resource.txt").toString()); + } + @Test public void testExtractHost() throws Exception { Assert.assertEquals(new HttpHost("localhost"),