Skip to content

Commit

Permalink
* load.c (loaded_feature_path): stop returning false negatives for
Browse files Browse the repository at this point in the history
  filenames which are trailing substrings of file extensions.  For
  example, 'b', which a trailing substring of ".rb" should not return
  false. [Bug #11155][ruby-core:69206]

* test/ruby/test_autoload.rb: test for fix

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
tenderlove committed May 16, 2015
1 parent fc7711f commit 1fc214c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Sun May 17 03:58:59 2015 Aaron Patterson <tenderlove@ruby-lang.org>

* load.c (loaded_feature_path): stop returning false negatives for
filenames which are trailing substrings of file extensions. For
example, 'b', which a trailing substring of ".rb" should not return
false. [Bug #11155][ruby-core:69206]

* test/ruby/test_autoload.rb: test for fix

Sat May 16 21:41:24 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>

* string.c: added documentation for character sequence \' with String#sub
Expand Down
2 changes: 1 addition & 1 deletion load.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ loaded_feature_path(const char *name, long vlen, const char *feature, long len,
const char *e;

if (vlen < len+1) return 0;
if (!strncmp(name+(vlen-len), feature, len)) {
if (strchr(feature, '.') && !strncmp(name+(vlen-len), feature, len)) {
plen = vlen - len;
}
else {
Expand Down
26 changes: 26 additions & 0 deletions test/ruby/test_autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ def test_autoload_p
}
end

def test_autoload_with_unqualified_file_name # [ruby-core:69206]
lp = $LOAD_PATH.dup
lf = $LOADED_FEATURES.dup

Dir.mktmpdir('autoload') { |tmpdir|
$LOAD_PATH << tmpdir

Dir.chdir(tmpdir) do
eval <<-END
class ::Object
module A
autoload :C, 'b'
end
end
END

File.open('b.rb', 'w') {|file| file.puts 'module A; class C; end; end'}
assert_kind_of Class, ::A::C
end
}
ensure
$LOAD_PATH.replace lp
$LOADED_FEATURES.replace lf
Object.send(:remove_const, :A) if Object.const_defined?(:A)
end

def test_require_explicit
Tempfile.create(['autoload', '.rb']) {|file|
file.puts 'class Object; AutoloadTest = 1; end'
Expand Down

0 comments on commit 1fc214c

Please sign in to comment.