8008166: URL handling was broken on windows, causing "load" to malfunction
authorlagergren
Wed, 20 Feb 2013 16:43:21 +0100
changeset 16251 4a5d15b2f168
parent 16250 96a7a6218ad3
child 16252 3bfe9b68a0fa
8008166: URL handling was broken on windows, causing "load" to malfunction Reviewed-by: attila, jlaskey Contributed-by: klara.ward@oracle.com
nashorn/make/build.xml
nashorn/src/jdk/nashorn/internal/runtime/Context.java
--- a/nashorn/make/build.xml	Wed Feb 20 17:08:32 2013 +0530
+++ b/nashorn/make/build.xml	Wed Feb 20 16:43:21 2013 +0100
@@ -211,6 +211,8 @@
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <!-- test/script/basic .js scripts load other script tests -->
     <echo message="    permission java.io.FilePermission &quot;${basedir}/test/script/-&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
+    <echo message="    permission java.io.FilePermission &quot;user.dir&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
+    <echo message="    permission java.util.PropertyPermission &quot;user.dir&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
     <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
     <!-- test/script/basic .js scripts can read nashorn.test.* properties -->
     <echo message="    permission java.util.PropertyPermission &quot;nashorn.test.*&quot;, &quot;read&quot;;" file="${build.dir}/nashorn.policy" append="true"/>
--- a/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Wed Feb 20 17:08:32 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/runtime/Context.java	Wed Feb 20 16:43:21 2013 +0100
@@ -37,7 +37,6 @@
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.reflect.Constructor;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.CodeSigner;
@@ -620,34 +619,28 @@
         // load accepts a String (which could be a URL or a file name), a File, a URL
         // or a ScriptObject that has "name" and "source" (string valued) properties.
         if (src instanceof String) {
-            String srcStr = (String)src;
-            final File file = new File((String)src);
+            final String srcStr = (String)src;
+            final File   file   = new File(srcStr);
             if (srcStr.indexOf(':') != -1) {
-                try {
-                    final URL url = new URL((String)src);
+                if (srcStr.startsWith("nashorn:")) {
+                    final String resource = "resources/" + srcStr.substring("nashorn:".length());
+                    // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
+                    // These scripts are always available and are loaded from nashorn.jar's resources.
+                    source = AccessController.doPrivileged(
+                            new PrivilegedAction<Source>() {
+                                @Override
+                                public Source run() {
+                                    try {
+                                        final URL resURL = Context.class.getResource(resource);
+                                        return (resURL != null)? new Source(srcStr, resURL) : null;
+                                    } catch (final IOException exp) {
+                                        return null;
+                                    }
+                                }
+                            });
+                } else {
+                    final URL url = file.toURI().toURL();
                     source = new Source(url.toString(), url);
-                } catch (final MalformedURLException e) {
-                    // fallback URL - nashorn:foo.js - check under jdk/nashorn/internal/runtime/resources
-                    final String str = (String)src;
-                    if (str.startsWith("nashorn:")) {
-                        final String resource = "resources/" + str.substring("nashorn:".length());
-                        // NOTE: even sandbox scripts should be able to load scripts in nashorn: scheme
-                        // These scripts are always available and are loaded from nashorn.jar's resources.
-                        source = AccessController.doPrivileged(
-                                new PrivilegedAction<Source>() {
-                                    @Override
-                                    public Source run() {
-                                        try {
-                                            final URL resURL = Context.class.getResource(resource);
-                                            return (resURL != null)? new Source(str, resURL) : null;
-                                        } catch (final IOException exp) {
-                                            return null;
-                                        }
-                                    }
-                                });
-                    } else {
-                        throw e;
-                    }
                 }
             } else if (file.isFile()) {
                 source = new Source(srcStr, file);