Skip to content

Commit

Permalink
[Truffle] Allows to require paths starting with "./"
Browse files Browse the repository at this point in the history
* Fixes #3079.
  • Loading branch information
eregon committed Jul 6, 2015
1 parent bce9d5c commit 539baf0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/kernel/require_tags.txt
@@ -1,16 +1,12 @@
fails:Kernel#require (path resolution) loads a non-canonical absolute path
fails:Kernel#require (path resolution) calls #to_str on non-String objects
fails:Kernel#require (path resolution) raises a TypeError if #to_str does not return a String
fails:Kernel#require (path resolution) calls #to_path on non-String objects
fails:Kernel#require (path resolution) calls #to_path on a String
fails:Kernel#require (path resolution) calls #to_str on non-String objects returned by #to_path
fails:Kernel#require (path resolution) loads a ./ relative path from the current working directory with empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a ../ relative path from the current working directory with empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a ./ relative path from the current working directory with non-empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a ../ relative path from the current working directory with non-empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a non-canonical path from the current working directory with non-empty $LOAD_PATH
fails:Kernel#require (path resolution) does not require file twice after $LOAD_PATH change
fails:Kernel#require (path resolution) does not resolve a ./ relative path against $LOAD_PATH entries
fails:Kernel#require (path resolution) does not resolve a ../ relative path against $LOAD_PATH entries
fails:Kernel#require (path resolution) loads a path with duplicate path separators
fails:Kernel#require (path resolution) with an unreadable file raises a LoadError
Expand All @@ -27,9 +23,7 @@ fails:Kernel#require ($LOAD_FEATURES) does not load a ../ relative path that is
fails:Kernel#require ($LOAD_FEATURES) does not load a non-canonical path that is already stored
fails:Kernel#require ($LOAD_FEATURES) does not load twice the same file with and without extension
fails:Kernel#require ($LOAD_FEATURES) stores ../ relative paths as absolute paths
fails:Kernel#require ($LOAD_FEATURES) stores ./ relative paths as absolute paths
fails:Kernel#require ($LOAD_FEATURES) collapses duplicate path separators
fails:Kernel#require ($LOAD_FEATURES) canonicalizes non-unique absolute paths
fails:Kernel#require ($LOAD_FEATURES) adds the suffix of the resolved filename
fails:Kernel#require ($LOAD_FEATURES) does not load a non-canonical path for a file already loaded
fails:Kernel#require ($LOAD_FEATURES) does not load a ./ relative path for a file already loaded
Expand Down
Expand Up @@ -11,6 +11,7 @@

import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;

import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.LexicalScope;
Expand Down Expand Up @@ -49,6 +50,11 @@ public FeatureManager(RubyContext context) {
public boolean require(String feature, Node currentNode) throws IOException {
final RubyConstant dataConstantBefore = ModuleOperations.lookupConstant(context, LexicalScope.NONE, context.getCoreLibrary().getObjectClass(), "DATA");

if (feature.startsWith("./")) {
final String cwd = context.getRuntime().getCurrentDirectory();
feature = cwd + "/" + feature;
}

try {
if (isAbsolutePath(feature)) {
// Try as a full path
Expand Down

0 comments on commit 539baf0

Please sign in to comment.