diff --git a/ChangeLog b/ChangeLog index 88866e64ca..35c8464d99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Sep 15 22:34:39 2014 Natalie Weizenbaum + + * 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 22:31:33 2014 Sho Hashimoto * 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 c61e613d9b..557fae35bc 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -1322,4 +1322,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 diff --git a/version.h b/version.h index 4cf2979696..9c7b05d8a0 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-09-15" -#define RUBY_PATCHLEVEL 239 +#define RUBY_PATCHLEVEL 240 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 9