mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Merge pull request #1379 from orangetw/master
enhanced path validation in Windows
This commit is contained in:
commit
6bcc6c3499
1 changed files with 4 additions and 1 deletions
|
@ -24,14 +24,17 @@ module Rack
|
|||
encoding = path.encoding
|
||||
dot = '.'.encode(encoding)
|
||||
slash = '/'.encode(encoding)
|
||||
backslash = '\\'.encode(encoding)
|
||||
else
|
||||
# Ruby 1.8
|
||||
dot = '.'
|
||||
slash = '/'
|
||||
backslash = '\\'
|
||||
end
|
||||
|
||||
parts = []
|
||||
unescaped = path.gsub(/%2e/i, dot).gsub(/%2f/i, slash)
|
||||
unescaped = path.gsub(/%2e/i, dot).gsub(/%2f/i, slash).gsub(/%5c/i, backslash)
|
||||
unescaped = unescaped.gsub(backslash, slash)
|
||||
|
||||
unescaped.split(slash).each do |part|
|
||||
next if part.empty? or part == dot
|
||||
|
|
Loading…
Add table
Reference in a new issue