class method
self.normalize_paths
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.normalize_paths(paths)
Returns an array of paths, cleaned of double-slashes and relative path references.
-
“\\” and “//” become “\” or “/”.
-
“/foo/bar/../config” becomes “/foo/config”.
The returned array is sorted by length, descending.
Parameters
-
pathsreq
Source
# File actionpack/lib/action_controller/routing.rb, line 299
def normalize_paths(paths)
# do the hokey-pokey of path normalization...
paths = paths.collect do |path|
path = path.
gsub("//", "/"). # replace double / chars with a single
gsub("\\\\", "\\"). # replace double \ chars with a single
gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it
# eliminate .. paths where possible
re = %r{[^/\\]+[/\\]\.\.[/\\]}
path.gsub!(re, "") while path.match(re)
path
end
# start with longest path, first
paths = paths.uniq.sort_by { |path| - path.length }
end
Defined in actionpack/lib/action_controller/routing.rb line 299
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::Routing