diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -4447,6 +4447,14 @@ file_load_ok(const char *path) return eaccess(path, R_OK) == 0; } +static int +is_explicit_relative(const char *path) +{ + if (*path++ != '.') return 0; + if (*path == '.') path++; + return isdirsep(*path); +} + VALUE rb_get_load_path(void); int @@ -4468,15 +4476,18 @@ rb_find_file_ext(VALUE *filep, const char *const *ext) *filep = fname; } - if (is_absolute_path(f)) { + if (is_absolute_path(f) || is_explicit_relative(f)) { + fname = rb_str_dup(*filep); + fnlen = RSTRING_LEN(fname); for (i=0; ext[i]; i++) { - fname = rb_str_dup(*filep); rb_str_cat2(fname, ext[i]); - OBJ_FREEZE(fname); if (file_load_ok(StringValueCStr(fname))) { + if (!is_absolute_path(f)) fname = rb_file_expand_path(fname, Qnil); + OBJ_FREEZE(fname); *filep = fname; return i+1; } + rb_str_set_len(fname, fnlen); } return 0; } @@ -4534,12 +4545,13 @@ rb_find_file(VALUE path) } #endif - if (is_absolute_path(f)) { + if (is_absolute_path(f) || is_explicit_relative(f)) { if (rb_safe_level() >= 1 && !fpath_check(f)) { rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } - if (file_load_ok(f)) return path; - return 0; + if (!file_load_ok(f)) return 0; + if (!is_absolute_path(f)) path = rb_file_expand_path(path, Qnil); + return path; } if (rb_safe_level() >= 4) { |