From 1f4efcbdd41dc5c57dbf9e47bf30b37cb37d746f Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Wed, 19 Apr 2006 10:50:02 +0000 Subject: [PATCH] escape none URL characters git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@395206 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/launch/Locator.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/launch/Locator.java b/src/main/org/apache/tools/ant/launch/Locator.java index 1322bcb8f..3fbf23c5b 100644 --- a/src/main/org/apache/tools/ant/launch/Locator.java +++ b/src/main/org/apache/tools/ant/launch/Locator.java @@ -401,7 +401,20 @@ public final class Locator { String path = location.getPath(); for (int i = 0; i < extensions.length; ++i) { if (path.toLowerCase().endsWith(extensions[i])) { - urls[0] = location.toURL(); + try { + /** + * File.toURL() does not encode characters like #. + * File.toURI() has been introduced in java 1.4, so + * ANT cannot use it (except by reflection) + * FileUtils.toURI() cannot be used by Locator.java + * Implemented this way. + * File.toURL() adds file: and changes '\' to '/' for dos OSes + * encodeUri converts characters like ' ' and '#' to %DD + */ + urls[0] = new URL(encodeUri(location.toURL().toString())); + } catch (UnsupportedEncodingException ex) { + throw new MalformedURLException(ex.toString()); + } break; } } @@ -420,7 +433,12 @@ public final class Locator { }); urls = new URL[matches.length]; for (int i = 0; i < matches.length; ++i) { - urls[i] = matches[i].toURL(); + try { + // See comments above. + urls[i] = new URL(encodeUri(matches[i].toURL().toString())); + } catch (UnsupportedEncodingException ex) { + throw new MalformedURLException(ex.toString()); + } } return urls; }