On 6/12/07, Gilles Scokart <[EMAIL PROTECTED]> wrote:
I notice a test error when my sources are loacted in a subdirectory of a directory containing a space. I fixed the unit-test that is now working, but I'm actuallu not sure that there is no bug into the code in such a case. Can you have a look?
I'm not sure either. According to me, a space in an URI is not valid, you have to escape it by a %20. So I think the bug is not in the code but in the caller (the test you fixed). So I'd say there is no bug in the code, but I'd better trust someone more proficient with either commons vfs or URI/URL concepts. Also, I copied a method taken from Wicket. Did we have to write it
somewhere?
I don't think so, but I may be wrong. If you don't get an answer, either ask again here with a specific subject (not sure mentors read this kind of thread), or ask on [EMAIL PROTECTED], Xavier Gilles
2007/6/12, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > Author: gscokart > Date: Tue Jun 12 00:07:33 2007 > New Revision: 546397 > > URL: http://svn.apache.org/viewvc?view=rev&rev=546397 > Log: > Fix test failure when URI contains spaces > > Modified: > incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/repository/vfs/VfsResourceTest.java > > Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/repository/vfs/VfsResourceTest.java > URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/repository/vfs/VfsResourceTest.java?view=diff&rev=546397&r1=546396&r2=546397 > ============================================================================== > --- incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/repository/vfs/VfsResourceTest.java (original) > +++ incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/repository/vfs/VfsResourceTest.java Tue Jun 12 00:07:33 2007 > @@ -24,6 +24,8 @@ > import java.util.Iterator; > import java.util.List; > > +import org.apache.commons.lang.StringUtils; > + > import junit.framework.TestCase; > > public class VfsResourceTest extends TestCase { > @@ -65,7 +67,7 @@ > // VFS apparently does some weird normalization so that resource id used to create > // the VFS resource is not necessarily identical to the id returned from the getName > // method <sigh>. We try to work around this by transforming things into java URIs. > - if (!new URI(resId).equals(new URI(res.getName()).normalize())) { > + if (!new URI(escapeUrl(resId)).equals(new URI(escapeUrl( res.getName())).normalize())) { > fail("Failed on getName. Expected: " + resId + ". Actual: " + res.getName()); > } > > @@ -84,6 +86,25 @@ > } > > /** > + * Escape invalid URL characters (Copied from Wicket, just use StringUtils instead of Strings) > + * > + * @param queryString The orginal querystring > + * @return url The querystring with invalid characters escaped > + */ > + private String escapeUrl(String queryString) { > + queryString = StringUtils.replace(queryString , " ", "%20"); > + queryString = StringUtils.replace(queryString , "\"", "%22"); > + queryString = StringUtils.replace(queryString , "%", "%26"); > + queryString = StringUtils.replace(queryString , "=", "%3D"); > + queryString = StringUtils.replace(queryString , "/", "%2F"); > + queryString = StringUtils.replace(queryString , "+", "%2B"); > + queryString = StringUtils.replace(queryString , "&", "%26"); > + queryString = StringUtils.replace(queryString , "~", "%7E"); > + queryString = StringUtils.replace(queryString , "?", "%3F"); > + return queryString; > + } > + > + /** > * Validating that resource can be created for files which don't physically exists - e.g. > * resources that are going to created. > */ > @@ -104,7 +125,7 @@ > // VFS apparently does some weird normalization so that resource id used to create > // the VFS resource is not necessarily identical to the id returned from the getName > // method <sigh>. We try to work around this by transforming things into java URIs. > - if (!new URI(resId).equals(new URI(res.getName()).normalize())) { > + if (!new URI(escapeUrl(resId)).equals(new URI(escapeUrl( res.getName())).normalize())) { > fail("Failed on getName. Expected: " + resId + ". Actual: " + res.getName()); > } > > > > -- Gilles SCOKART
-- Xavier Hanin - Independent Java Consultant Manage your dependencies with Ivy! http://incubator.apache.org/ivy/
