From 9e395140343025ec7a5e738a28e364fbd749c0cc Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Thu, 28 Jun 2018 10:27:26 +0530 Subject: [PATCH] bz-62499 Revert the change which caused regression in "get" task. Plus introduce a test case to reproduce the issue and verify the fix --- .../org/apache/tools/ant/taskdefs/Get.java | 41 +++++++++++-------- src/tests/antunit/taskdefs/get-test.xml | 9 ++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java index 13f610c53..1d4ba4f83 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Get.java +++ b/src/main/org/apache/tools/ant/taskdefs/Get.java @@ -669,29 +669,34 @@ public class Get extends Task { private boolean redirectionAllowed(final URL aSource, final URL aDest) { - if (aSource.getProtocol().equals(aDest.getProtocol()) - && (HTTP.equals(aSource.getProtocol()) || HTTPS.equals(aDest.getProtocol()))) { - redirections++; - if (redirections > REDIRECT_LIMIT) { - final String message = "More than " + REDIRECT_LIMIT - + " times redirected, giving up"; - if (ignoreErrors) { - log(message, logLevel); - return false; - } + if (!(aSource.getProtocol().equals(aDest.getProtocol()) || (HTTP + .equals(aSource.getProtocol()) && HTTPS.equals(aDest + .getProtocol())))) { + final String message = "Redirection detected from " + + aSource.getProtocol() + " to " + aDest.getProtocol() + + ". Protocol switch unsafe, not allowed."; + if (ignoreErrors) { + log(message, logLevel); + return false; + } else { throw new BuildException(message); } - return true; } - final String message = "Redirection detected from " - + aSource.getProtocol() + " to " + aDest.getProtocol() - + ". Protocol switch unsafe, not allowed."; - if (ignoreErrors) { - log(message, logLevel); - return false; + redirections++; + if (redirections > REDIRECT_LIMIT) { + final String message = "More than " + REDIRECT_LIMIT + + " times redirected, giving up"; + if (ignoreErrors) { + log(message, logLevel); + return false; + } else { + throw new BuildException(message); + } } - throw new BuildException(message); + + + return true; } private URLConnection openConnection(final URL aSource) throws IOException { diff --git a/src/tests/antunit/taskdefs/get-test.xml b/src/tests/antunit/taskdefs/get-test.xml index a8ca6a911..b4543f579 100644 --- a/src/tests/antunit/taskdefs/get-test.xml +++ b/src/tests/antunit/taskdefs/get-test.xml @@ -122,4 +122,13 @@ + + + + + + + +