diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-17 06:09:51 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-17 06:09:51 +0000 |
commit | 95285e34575777ab42daf3070477814674c67ad0 (patch) | |
tree | 6c4d02b69d23c4c0f5f60e8074d73f7ec8205b0c | |
parent | 8676e7a9bcb2e41141b019941de85e6b1ad0b33d (diff) |
merge revision(s) 47591: [Backport #10242]
* 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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/pathname/lib/pathname.rb | 3 | ||||
-rw-r--r-- | test/pathname/test_pathname.rb | 13 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 24 insertions, 2 deletions
@@ -1,3 +1,11 @@ +Wed Sep 17 15:09:16 2014 Natalie Weizenbaum <nweiz@google.com> + + * 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] + Wed Sep 17 15:07:35 2014 Sho Hashimoto <sho.hsmt@gmail.com> * ext/fiddle/lib/fiddle/import.rb (Fiddle::Importer#sizeof): fix typo, diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index e7e47ceac6..8bce81ea10 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -22,7 +22,8 @@ class Pathname 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 diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 03e09bfb6f..ba3686f740 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -1306,4 +1306,17 @@ class TestPathname < Test::Unit::TestCase 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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-09-17" -#define RUBY_PATCHLEVEL 573 +#define RUBY_PATCHLEVEL 574 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 9 |