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

ruby-changes:35509

From: nobu <ko1@a...>
Date: Mon, 15 Sep 2014 10:29:28 +0900 (JST)
Subject: [ruby-changes:35509] nobu:r47591 (trunk): pathname.rb: fix a Pathname#relative_path_from crash on

nobu	2014-09-15 10:29:21 +0900 (Mon, 15 Sep 2014)

  New Revision: 47591

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

  Log:
    pathname.rb: fix a Pathname#relative_path_from crash on
    
    * ext/pathname/lib/pathname.rb (SAME_PATHS):
      Pathname#relative_path_from uses String#casecmp to compare strings
      on case-insensitive filesystem platforms (e.g., Windows). This can
      return nil for strings with different encodings, and the code
      previously assumed that it always returned a Fixnum.  [Fix GH-713]

  Modified files:
    trunk/ChangeLog
    trunk/ext/pathname/lib/pathname.rb
    trunk/test/pathname/test_pathname.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47590)
+++ ChangeLog	(revision 47591)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Sep 15 10:29:25 2014  Natalie Weizenbaum  <nweiz@g...>
+
+	* ext/pathname/lib/pathname.rb (SAME_PATHS):
+	  Pathname#relative_path_from uses String#casecmp to compare strings
+	  on case-insensitive filesystem platforms (e.g., Windows). This can
+	  return nil for strings with different encodings, and the code
+	  previously assumed that it always returned a Fixnum.  [Fix GH-713]
+
 Mon Sep 15 09:43:18 2014  Sho Hashimoto  <sho.hsmt@g...>
 
 	* ext/fiddle/lib/fiddle/import.rb (Fiddle::Importer#sizeof): fix typo,
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 47590)
+++ ext/pathname/lib/pathname.rb	(revision 47591)
@@ -22,7 +22,8 @@ class Pathname https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L22
   end
 
   SAME_PATHS = if File::FNM_SYSCASE.nonzero?
-    proc {|a, b| a.casecmp(b).zero?}
+    # Avoid #zero? here because #casecmp can return nil.
+    proc {|a, b| a.casecmp(b) == 0}
   else
     proc {|a, b| a == b}
   end
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 47590)
+++ test/pathname/test_pathname.rb	(revision 47591)
@@ -1374,4 +1374,17 @@ class TestPathname < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L1374
       assert_equal("foo/bar", File.join(Pathname.new("foo"), Pathname.new("bar").taint))
     }.call
   end
+
+  def test_relative_path_from_casefold
+    assert_separately([], <<-'end;') #    do
+      module File::Constants
+        remove_const :FNM_SYSCASE
+        FNM_SYSCASE = FNM_CASEFOLD
+      end
+      require 'pathname'
+      foo = Pathname.new("fo\u{f6}")
+      bar = Pathname.new("b\u{e4}r".encode("ISO-8859-1"))
+      assert_instance_of(Pathname, foo.relative_path_from(bar))
+    end;
+  end
 end

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

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