Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix so require_relative can handle an absolute path. #571

Merged
merged 1 commit into from

2 participants

@yb66

require_relative was failing for me when passed an absolute path to a file. I've updated the specs on rubyspecs because they weren't checking for an absolute path being passed (commit #95e39ad659).

The code I've changed here was concatenating an absolute path to either another absolute path (where it failed), or it still left dots in the path (which seemed strange), before passing it to require. I've updated it, but I can't run a high enough version of ant on my machine to run the specs against it (the curse of Apple). Hopefully it works, apologies if not.

Regards,
Iain

@yb66 yb66 require_relative fails when passed an absolute path. Changes mean it …
…should now handle both relative and absolute without errors.
a8c172a
@headius headius merged commit e6fcf42 into jruby:master
@headius
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 10, 2013
  1. @yb66

    require_relative fails when passed an absolute path. Changes mean it …

    yb66 authored
    …should now handle both relative and absolute without errors.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 src/jruby/kernel19/kernel.rb
View
6 src/jruby/kernel19/kernel.rb
@@ -10,12 +10,12 @@ def require_relative(relative_feature)
relative_feature = JRuby::Type.convert_to_str(relative_feature)
c = caller.first
- e = c.rindex(/:\d+:in /)
- file = $`
+ e = c.rindex(/:\d+:in /)
+ file = $` # just the filename
if /\A\((.*)\)/ =~ file # eval, etc.
raise LoadError, "cannot infer basepath"
end
- absolute_feature = File.join(File.dirname(File.realpath(file)), relative_feature)
+ absolute_feature = File.expand_path(relative_feature, File.dirname(file))
require absolute_feature
end
Something went wrong with that request. Please try again.