Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rentzsch
Created February 8, 2013 05:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rentzsch/4736940 to your computer and use it in GitHub Desktop.
Save rentzsch/4736940 to your computer and use it in GitHub Desktop.
require 'pp'
SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact)
def inspectPath(path_info)
parts = path_info.split SEPS
parts.inject(0) do |depth, part|
case part
when '', '.'
depth
when '..'
throw 'climb-out detected' if depth - 1 < 0
depth - 1
else
depth + 1
end
end
parts
end
pp inspectPath('./..')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment