Skip to content

Commit

Permalink
[GR-19220] Convert string arg to Pathname in relative_path_from
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3830
  • Loading branch information
andrykonchin authored and eregon committed May 25, 2023
2 parents 404a086 + 7b4fd94 commit ab9f1a6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Compatibility:
* Fix `Array#[]` with `ArithmeticSequence` argument when step is negative (#3039, @itarato).
* Fix `Range#size` and return `nil` for beginningless Range when end isn't Numeric (#3039, @rwstauner).
* Alias `String#-@` to `String#dedup` (#3039, @itarato).
* Fix `Pathname#relative_path_from` to convert string arguments to Pathname objects (@rwstauner).

Performance:

Expand Down
1 change: 1 addition & 0 deletions lib/truffle/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ def each_child(with_directory = true, &b)
# This method has existed since 1.8.1.
#
def relative_path_from(base_directory)
base_directory = Pathname.new(base_directory) unless Primitive.is_a?(base_directory, Pathname)
dest_directory = self.cleanpath.to_s
base_directory = base_directory.cleanpath.to_s
dest_prefix = dest_directory
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/library/pathname/relative_path_from_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ def relative_path_str(dest, base)
relative_path_str('..', '..').should == '.'
relative_path_str('..', '.').should == '..'
end

it 'converts string argument to Pathname' do
Pathname.new('/usr/bin/ls').relative_path_from('/usr').to_s.should == 'bin/ls'
end
end

0 comments on commit ab9f1a6

Please sign in to comment.