Mercurial Hosting > luan
diff core/src/luan/modules/Utils.java @ 203:99eef1d0e706
IO security
git-svn-id: https://luan-java.googlecode.com/svn/trunk@204 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 06 Jul 2014 03:54:08 +0000 |
parents | 1cb298d918b2 |
children | a1b142f9c5c0 |
line wrap: on
line diff
--- a/core/src/luan/modules/Utils.java Fri Jul 04 17:18:39 2014 +0000 +++ b/core/src/luan/modules/Utils.java Sun Jul 06 03:54:08 2014 +0000 @@ -60,11 +60,14 @@ } } - public static boolean isFile(String path) { - return !path.contains("//") && exists(new File(path)); + public static File toFile(String path) { + if( path.contains("//") ) + return null; + File file = new File(path); + return exists(file) ? file : null; } - public static String toUrl(String path) { + public static URL toUrl(String path) { if( path.indexOf(':') == -1 ) return null; if( path.startsWith("java:") ) { @@ -72,16 +75,15 @@ if( path.contains("//") ) return null; URL url = ClassLoader.getSystemResource(path); - return url==null ? null : url.toString(); + return url==null ? null : url; } try { - new URL(path); - return path; + return new URL(path); } catch(MalformedURLException e) {} return null; } public static boolean exists(String path) { - return isFile(path) || toUrl(path)!=null; + return toFile(path)!=null || toUrl(path)!=null; } }