[前][次][番号順一覧][スレッド一覧]

ruby-changes:38434

From: tenderlove <ko1@a...>
Date: Sun, 17 May 2015 04:03:09 +0900 (JST)
Subject: [ruby-changes:38434] tenderlove:r50515 (trunk): * load.c (loaded_feature_path): stop returning false negatives for

tenderlove	2015-05-17 04:02:38 +0900 (Sun, 17 May 2015)

  New Revision: 50515

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50515

  Log:
    * 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

  Modified files:
    trunk/ChangeLog
    trunk/load.c
    trunk/test/ruby/test_autoload.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50514)
+++ ChangeLog	(revision 50515)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May 17 03:58:59 2015  Aaron Patterson <tenderlove@r...>
+
+	* 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@r...>
 
 	* string.c: added documentation for character sequence \' with String#sub
Index: load.c
===================================================================
--- load.c	(revision 50514)
+++ load.c	(revision 50515)
@@ -317,7 +317,7 @@ loaded_feature_path(const char *name, lo https://github.com/ruby/ruby/blob/trunk/load.c#L317
     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 {
Index: test/ruby/test_autoload.rb
===================================================================
--- test/ruby/test_autoload.rb	(revision 50514)
+++ test/ruby/test_autoload.rb	(revision 50515)
@@ -55,6 +55,32 @@ p Foo::Bar https://github.com/ruby/ruby/blob/trunk/test/ruby/test_autoload.rb#L55
     }
   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'

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]