Skip to content

Commit

Permalink
JRUBY-2722: Interpreter passes absolute path to the EventHook for 're…
Browse files Browse the repository at this point in the history
…quire'ed files

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@7198 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information
enebo committed Jul 17, 2008
1 parent 03c1378 commit 50bad77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/org/jruby/Ruby.java
Expand Up @@ -1830,9 +1830,18 @@ public IRubyObject setValue(IRubyObject newValue) {
public void defineReadonlyVariable(String name, IRubyObject value) {
globalVariables.defineReadonly(name, new ValueAccessor(value));
}

/* FIXME: Helper method...we need to do something better than this */
private String tweakPath(String filename) {
File f = new File(filename);

if (f.exists() && !f.isAbsolute() && !filename.startsWith("./")) filename = "./" + filename;

return filename;
}

public Node parseFile(InputStream in, String file, DynamicScope scope) {
return parser.parse(file, in, scope, new ParserConfiguration(0, false, false, true));
return parser.parse(tweakPath(file), in, scope, new ParserConfiguration(0, false, false, true));
}

public Node parseInline(InputStream in, String file, DynamicScope scope) {
Expand Down Expand Up @@ -2027,22 +2036,12 @@ private void printErrorPos(ThreadContext context, PrintStream errorStream) {
}

public void loadFile(String scriptName, InputStream in, boolean wrap) {
if (!Ruby.isSecurityRestricted()) {
File f = new File(scriptName);
if(f.exists() && !f.isAbsolute() && !scriptName.startsWith("./")) {
scriptName = "./" + scriptName;
}
}
if (!Ruby.isSecurityRestricted()) scriptName = tweakPath(scriptName);

IRubyObject self = null;
if (wrap) {
self = TopSelfFactory.createTopSelf(this);
} else {
self = getTopSelf();
}
IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this) : getTopSelf();
ThreadContext context = getCurrentContext();

String file = context.getFile();

try {
secure(4); /* should alter global state */

Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/runtime/load/LoadService.java
Expand Up @@ -494,7 +494,7 @@ private LoadServiceResource findFile(String name, boolean checkCWD) {
RubyFile.expandUserPath(runtime.getCurrentContext(), name));
if (current.isFile()) {
try {
return new LoadServiceResource(current.toURI().toURL(), current.getPath());
return new LoadServiceResource(current.toURI().toURL(), name);
} catch (MalformedURLException e) {
throw runtime.newIOErrorFromException(e);
}
Expand Down
Empty file removed test/test_trace_func.rb
Empty file.

0 comments on commit 50bad77

Please sign in to comment.