Skip to content

Commit e87486f

Browse files
author
Niall Pemberton
committed
IO-163 Change FileUtils.toURLs() to use File.toURI().toURL() rather than File.toURL() - thanks to Alex Miller for the suggestion
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@647000 13f79535-47bb-0310-9956-ffa450edef68
1 parent c3b706a commit e87486f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/java/org/apache/commons/io/FileUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public static URL[] toURLs(File[] files) throws IOException {
532532
URL[] urls = new URL[files.length];
533533

534534
for (int i = 0; i < urls.length; i++) {
535-
urls[i] = files[i].toURL();
535+
urls[i] = files[i].toURI().toURL();
536536
}
537537

538538
return urls;

src/test/org/apache/commons/io/FileUtilsTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public void testToURLs1() throws Exception {
328328
File[] files = new File[] {
329329
new File(getTestDirectory(), "file1.txt"),
330330
new File(getTestDirectory(), "file2.txt"),
331+
new File(getTestDirectory(), "test file.txt"),
331332
};
332333
URL[] urls = FileUtils.toURLs(files);
333334

@@ -336,6 +337,10 @@ public void testToURLs1() throws Exception {
336337
assertEquals(true, urls[0].toExternalForm().indexOf("file1.txt") >= 0);
337338
assertEquals(true, urls[1].toExternalForm().startsWith("file:"));
338339
assertEquals(true, urls[1].toExternalForm().indexOf("file2.txt") >= 0);
340+
341+
// Test escaped char
342+
assertEquals(true, urls[2].toExternalForm().startsWith("file:"));
343+
assertEquals(true, urls[2].toExternalForm().indexOf("test%20file.txt") >= 0);
339344
}
340345

341346
// public void testToURLs2() throws Exception {

0 commit comments

Comments
 (0)