Author: mes
Date: 2010-02-09 14:51:41 -0800 (Tue, 09 Feb 2010)
New Revision: 19276

Added:
   cytoscape/trunk/tests/cytoscape/util/FileUtilTest.java
Modified:
   cytoscape/trunk/src/cytoscape/util/FileUtil.java
Log:
Updated URL regular expression and added a unit test to allow future validation 
of new problematic urls. Re: 2024

Modified: cytoscape/trunk/src/cytoscape/util/FileUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/FileUtil.java    2010-02-09 22:06:50 UTC 
(rev 19275)
+++ cytoscape/trunk/src/cytoscape/util/FileUtil.java    2010-02-09 22:51:41 UTC 
(rev 19276)
@@ -86,7 +86,8 @@
         * A string that defines a simplified java regular expression for a URL.
         * This may need to be updated to be more precise.
         */
-       public static final String urlPattern = 
"^(jar\\:)?(\\w+\\:\\/+\\S+)(\\!\\/\\S*)?$";
+       public static final String urlPattern = 
+               "^(jar\\:)?((http|https|ftp|file)+\\:\\/+\\S+)(\\!\\/\\S*)?$";
 
        /**
         * Returns a File object, this method should be used instead

Added: cytoscape/trunk/tests/cytoscape/util/FileUtilTest.java
===================================================================
--- cytoscape/trunk/tests/cytoscape/util/FileUtilTest.java                      
        (rev 0)
+++ cytoscape/trunk/tests/cytoscape/util/FileUtilTest.java      2010-02-09 
22:51:41 UTC (rev 19276)
@@ -0,0 +1,66 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package cytoscape.util;
+
+import junit.framework.*;
+
+import java.util.regex.Pattern;
+
+
+public class FileUtilTest extends TestCase {
+
+       Pattern p = Pattern.compile(FileUtil.urlPattern);       
+
+       public void testRegExPattern() {
+               // normal
+               checkURL("http://chianti.ucsd.edu/file.sif";, true ); 
+               checkURL("https://chianti.ucsd.edu/file.xgmml";, true );
+               checkURL("ftp://chianti.ucsd.edu/file.cys";, true );
+               checkURL("file://chianti.ucsd.edu/file.cys", true );
+
+               // java jar extension
+               checkURL("jar:http://chianti.ucsd.edu/file.sif";, true ); 
+               checkURL("jar:https://chianti.ucsd.edu/file.xgmml";, true );
+               checkURL("jar:ftp://chianti.ucsd.edu/file.cys";, true );
+               checkURL("jar:file://chianti.ucsd.edu/file.cys", true );
+
+               // bad
+               checkURL("C:/galFiltered.sif", false );  // bug 2024
+       }
+
+       private void checkURL(String url, boolean expected) {
+               assertEquals( p.matcher(url).matches(), expected );
+       }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to