Skip to content

Commit

Permalink
Fixed the bug #10 -
Browse files Browse the repository at this point in the history
  • Loading branch information
marubinotto committed Jun 12, 2011
1 parent ef3601a commit 607667b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -12,6 +14,7 @@

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.UnhandledException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -101,11 +104,21 @@ public String getUrl() throws IOException {
private static boolean isInMemoryPrefix(String prefix) {
return prefix.startsWith("mem:");
}

public static String toUrlWithoutEscape(File file) {
String url = file.toURI().toString();
try {
return URLDecoder.decode(url, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new UnhandledException(e);
}
}

private static String preparePrefix(String original) throws Exception {
String prepared = null;
if (original.startsWith("~") || original.startsWith("file:~")) {
String homeUrl = FileSystemUtils.getUserHome(false).toURI().toString(); // FIXME URL should not be escaped
String homeUrl = toUrlWithoutEscape(FileSystemUtils.getUserHome(false));
if (homeUrl.endsWith("/")) homeUrl = StringUtils.chop(homeUrl);
prepared = homeUrl + original.substring(original.indexOf('~') + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

import java.io.File;

import org.junit.Test;
import org.springframework.mock.web.MockServletContext;

Expand Down Expand Up @@ -95,4 +97,11 @@ public void databaseName_fromDeployName_onlySlash() throws Exception {
this.object.setServletContext(context);
assertEquals(H2JdbcUrl.DEFAULT_DATABASE_NAME, this.object.getDatabaseName());
}

@Test
public void toUrlWithoutEscape() throws Exception {
String result = H2JdbcUrl.toUrlWithoutEscape(new File("/my docs"));
System.out.println("toUrlWithoutEscape: " + result);
assertTrue("URL should not be escaped", result.indexOf("my docs") != -1);
}
}

0 comments on commit 607667b

Please sign in to comment.