diff --git a/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java b/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java index 03970cd75..6d5e73ae0 100644 --- a/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java +++ b/engine/src/desktop/com/jme3/asset/plugins/ClasspathLocator.java @@ -34,10 +34,13 @@ package com.jme3.asset.plugins; import com.jme3.asset.*; import com.jme3.system.JmeSystem; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -103,12 +106,33 @@ public class ClasspathLocator implements AssetLocator { if (url == null) return null; + if (url.getProtocol().equals("file")){ + try { + String path = new File(url.toURI()).getCanonicalPath(); + + // convert to / for windows + if (File.separatorChar == '\\'){ + path = path.replace('\\', '/'); + } + + // compare path + if (!path.endsWith(name)){ + throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ + "\"" + path + "\" doesn't match \"" + name + "\""); + } + } catch (URISyntaxException ex) { + throw new AssetLoadException("Error converting URL to URI", ex); + } catch (IOException ex){ + throw new AssetLoadException("Failed to get canonical path for " + url, ex); + } + } + try{ URLConnection conn = url.openConnection(); conn.setUseCaches(false); return new ClasspathAssetInfo(manager, key, conn); }catch (IOException ex){ - return null; + throw new AssetLoadException("Failed to read URL " + url, ex); } }