pathname2 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,4 +1,9 @@
1
- == 1.4.1 - 18-Feb-2005
1
+ == 1.4.2 - 22-Feb-2006
2
+ * Fixed the Pathname#relative_path_from method for Windows. This really only
3
+ affected edge cases that you probably never saw anyway.
4
+ * Added corresponding tests for Windows.
5
+
6
+ == 1.4.1 - 18-Feb-2006
2
7
  * Added the Pathname#parent method.
3
8
  * Added the Pathname#relative_path_from method.
4
9
  * Bug fix for Pathname#pstrip on *nix.
data/lib/pathname2.rb CHANGED
@@ -77,7 +77,7 @@ class Pathname < String
77
77
  Win32API.new("shlwapi", "PathRemoveBackslash", "P", "P")
78
78
  end
79
79
 
80
- VERSION = "1.4.1"
80
+ VERSION = "1.4.2"
81
81
  MAX_PATH = 260
82
82
 
83
83
  # Creates and returns a new Pathname object.
@@ -376,6 +376,8 @@ class Pathname < String
376
376
  # the argument must be relative too.
377
377
  #
378
378
  # This method does not access the filesystem. It assumes no symlinks.
379
+ # You should only compare directories against directories, or files against
380
+ # files, or you may not get expected results.
379
381
  #
380
382
  # Raises an ArgumentError if it cannot find a relative path.
381
383
  def relative_path_from(base)
@@ -387,6 +389,14 @@ class Pathname < String
387
389
 
388
390
  return Pathname.new(".") if self == base
389
391
  return self if base == "."
392
+
393
+ # Because of the way the Windows version handles Pathname#clean, we need
394
+ # a little extra help here.
395
+ if @win
396
+ if base == '..' && (self != '..' || self != '.')
397
+ raise ArgumentError, "base directory may not contain '..'"
398
+ end
399
+ end
390
400
 
391
401
  dest_arr = self.clean.to_a
392
402
  base_arr = base.clean.to_a
data/test/tc_pathname.rb CHANGED
@@ -71,7 +71,7 @@ class TC_Pathname < Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  def test_version
74
- assert_equal("1.4.1", Pathname::VERSION)
74
+ assert_equal("1.4.2", Pathname::VERSION)
75
75
  end
76
76
 
77
77
  # These tests taken directly from Tanaka's pathname.rb. The one failure
@@ -50,7 +50,7 @@ class TC_Pathname_MSWin < Test::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_version
53
- assert_equal("1.4.0", Pathname::VERSION)
53
+ assert_equal("1.4.2", Pathname::VERSION)
54
54
  end
55
55
 
56
56
  # Convenience method for test_plus
@@ -69,6 +69,58 @@ class TC_Pathname_MSWin < Test::Unit::TestCase
69
69
  assert_equal(int, result)
70
70
  end
71
71
 
72
+ # Convenience method for test_relative_path_from
73
+ def assert_relpath(result, dest, base)
74
+ assert_equal(result, Pathname.new(dest).relative_path_from(base))
75
+ end
76
+
77
+ # Convenience method for test_relative_path_from_expected_errors
78
+ def assert_relpath_err(to, from)
79
+ assert_raise(ArgumentError) {
80
+ Pathname.new(to).relative_path_from(from)
81
+ }
82
+ end
83
+
84
+ def test_relative_path_from
85
+ assert_relpath("..\\a", "a", "b")
86
+ assert_relpath("..\\a", "a", "b\\")
87
+ assert_relpath("..\\a", "a\\", "b")
88
+ assert_relpath("..\\a", "a\\", "b\\")
89
+ assert_relpath("..\\a", "c:\\a", "c:\\b")
90
+ assert_relpath("..\\a", "c:\\a", "c:\\b\\")
91
+ assert_relpath("..\\a", "c:\\a\\", "c:\\b")
92
+ assert_relpath("..\\a", "c:\\a\\", "c:\\b\\")
93
+
94
+ assert_relpath("..\\b", "a\\b", "a\\c")
95
+ assert_relpath("..\\a", "..\\a", "..\\b")
96
+
97
+ assert_relpath("a", "a", ".")
98
+ assert_relpath("..", ".", "a")
99
+
100
+ assert_relpath(".", ".", ".")
101
+ assert_relpath(".", "..", "..")
102
+ assert_relpath("..", "..", ".")
103
+
104
+ assert_relpath("c\\d", "c:\\a\\b\\c\\d", "c:\\a\\b")
105
+ assert_relpath("..\\..", "c:\\a\\b", "c:\\a\\b\\c\\d")
106
+ assert_relpath("..\\..\\..\\..\\e", "c:\\e", "c:\\a\\b\\c\\d")
107
+ assert_relpath("..\\b\\c", "a\\b\\c", "a\\d")
108
+
109
+ assert_relpath("..\\a", "c:\\..\\a", "c:\\b")
110
+ #assert_relpath("..\\..\\a", "..\\a", "b") # fails
111
+ assert_relpath(".", "c:\\a\\..\\..\\b", "c:\\b")
112
+ assert_relpath("..", "a\\..", "a")
113
+ assert_relpath(".", "a\\..\\b", "b")
114
+
115
+ assert_relpath("a", "a", "b\\..")
116
+ assert_relpath("b\\c", "b\\c", "b\\..")
117
+
118
+ assert_relpath_err("c:\\", ".")
119
+ assert_relpath_err(".", "c:\\")
120
+ assert_relpath_err("a", "..")
121
+ assert_relpath_err(".", "..")
122
+ end
123
+
72
124
  # Convenience method to verify that the receiver was not modified
73
125
  # except perhaps slashes
74
126
  def assert_non_destructive
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: pathname2
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.4.1
7
- date: 2006-02-18
6
+ version: 1.4.2
7
+ date: 2006-02-22 00:00:00 -07:00
8
8
  summary: An alternate implementation of the Pathname class
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: djberg96@gmail.com
12
12
  homepage: http://www.rubyforge.org/projects/shards
13
13
  rubyforge_project:
@@ -18,38 +18,42 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
26
+ signing_key:
27
+ cert_chain:
27
28
  authors:
28
- - Daniel J. Berger
29
+ - Daniel J. Berger
29
30
  files:
30
- - lib/pathname2.rb
31
- - README
32
- - CHANGES
33
- - MANIFEST
34
- - test/tc_pathname_win.rb
35
- - test/tc_pathname.rb
31
+ - lib/pathname2.rb
32
+ - CHANGES
33
+ - MANIFEST
34
+ - README
35
+ - test/tc_pathname.rb
36
+ - test/tc_pathname_win.rb
36
37
  test_files:
37
- - test/tc_pathname.rb
38
+ - test/tc_pathname.rb
38
39
  rdoc_options: []
40
+
39
41
  extra_rdoc_files:
40
- - README
41
- - CHANGES
42
+ - README
43
+ - CHANGES
42
44
  executables: []
45
+
43
46
  extensions: []
47
+
44
48
  requirements: []
49
+
45
50
  dependencies:
46
- - !ruby/object:Gem::Dependency
47
- name: facade
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Version::Requirement
50
- requirements:
51
- -
52
- - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.0.0
55
- version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: facade
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Version::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.0.0
59
+ version: