You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ma...@apache.org on 2008/09/02 22:13:38 UTC
svn commit: r691363 - in /ant/ivy/core/trunk: CHANGES.txt
src/java/org/apache/ivy/util/url/BasicURLHandler.java
Author: maartenc
Date: Tue Sep 2 13:13:38 2008
New Revision: 691363
URL: http://svn.apache.org/viewvc?rev=691363&view=rev
Log:
FIX: Invalid URL when using dynamic ranges (IVY-885)
Modified:
ant/ivy/core/trunk/CHANGES.txt
ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java
Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=691363&r1=691362&r2=691363&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Tue Sep 2 13:13:38 2008
@@ -110,6 +110,7 @@
- IMPROVEMENT: Add a memory cache for the module descriptor that are parsed from the cache (IVY-883)
- IMPROVEMENT: Improve performance (IVY-872)
+- FIX: Invalid URL when using dynamic ranges (IVY-885)
- FIX: can't use gotoNode with a node which has not been visited yet (IVY-874)
- FIX: Ivy Publish Task Fails When XML Comments Exist Next to Dependency Declarations (IVY-888)
- FIX: Incorrect directory path resolve when running from a different directory (IVY-232)
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java?rev=691363&r1=691362&r2=691363&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/BasicURLHandler.java Tue Sep 2 13:13:38 2008
@@ -19,9 +19,14 @@
import java.io.*;
import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.ivy.Ivy;
import org.apache.ivy.util.CopyProgressListener;
@@ -32,6 +37,8 @@
*
*/
public class BasicURLHandler extends AbstractURLHandler {
+
+ private static final Pattern ESCAPE_PATTERN = Pattern.compile("%25([0-9a-fA-F][0-9a-fA-F])");
private static final int BUFFER_SIZE = 64 * 1024;
@@ -58,6 +65,7 @@
public URLInfo getURLInfo(URL url, int timeout) {
URLConnection con = null;
try {
+ url = normalize(url);
con = url.openConnection();
con.setRequestProperty("User-Agent", "Apache Ivy/" + Ivy.getIvyVersion());
if (con instanceof HttpURLConnection) {
@@ -86,6 +94,26 @@
return UNAVAILABLE;
}
+ private URL normalize(URL url) throws IOException {
+ if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol())) {
+ try {
+ URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
+ url.getPort(), url.getPath(), url.getQuery(), url.getRef());
+
+ // it is possible that the original url was already (partial) escaped,
+ // so we must unescape all '%' followed by 2 hexadecimals...
+ String uriString = uri.toString();
+ url = new URL(ESCAPE_PATTERN.matcher(uriString).replaceAll("%$1"));
+ } catch (URISyntaxException e) {
+ IOException ioe = new MalformedURLException("Couldn't convert '" +
+ url.toString() + "' to a valid URI");
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+ return url;
+ }
+
private boolean checkStatusCode(URL url, HttpURLConnection con) throws IOException {
int status = con.getResponseCode();
if (status == HttpStatus.SC_OK) {
@@ -108,6 +136,7 @@
URLConnection conn = null;
InputStream inStream = null;
try {
+ url = normalize(url);
conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Apache Ivy/" + Ivy.getIvyVersion());
if (conn instanceof HttpURLConnection) {
@@ -139,6 +168,7 @@
public void download(URL src, File dest, CopyProgressListener l) throws IOException {
URLConnection srcConn = null;
try {
+ src = normalize(src);
srcConn = src.openConnection();
srcConn.setRequestProperty("User-Agent", "Apache Ivy/" + Ivy.getIvyVersion());
if (srcConn instanceof HttpURLConnection) {
@@ -174,6 +204,7 @@
HttpURLConnection conn = null;
try {
+ dest = normalize(dest);
conn = (HttpURLConnection) dest.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");