Skip to content

Instantly share code, notes, and snippets.

@eam
Created November 14, 2012 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eam/4069375 to your computer and use it in GitHub Desktop.
Save eam/4069375 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'pathname'
system "rm -rf /tmp/x /tmp/foo"
Dir.mkdir "/tmp/x"
Dir.mkdir "/tmp/x/y"
File.open "/tmp/x/y/z", "w" do |f|
f.puts "hello world"
end
Dir.chdir "/tmp"
File.symlink "/tmp/x/y", "foo"
orig_path = "/tmp/foo/../y/z"
File.stat "/tmp/foo/z" # works
File.stat orig_path # works
puts "all these work so far, now let's cleanpath it"
clean_path = Pathname.new(orig_path).cleanpath
File.stat clean_path # fails, because of a faulty path cleaning algorithm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment