Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rack-protection] Drop Ruby 1.8 compat code #1528

Merged
merged 2 commits into from May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions rack-protection/lib/rack/protection/path_traversal.rb
Expand Up @@ -19,18 +19,10 @@ def call(env)
end

def cleanup(path)
if path.respond_to?(:encoding)
# Ruby 1.9+ M17N
encoding = path.encoding
dot = '.'.encode(encoding)
slash = '/'.encode(encoding)
backslash = '\\'.encode(encoding)
else
# Ruby 1.8
dot = '.'
slash = '/'
backslash = '\\'
end
encoding = path.encoding
dot = '.'.encode(encoding)
slash = '/'.encode(encoding)
backslash = '\\'.encode(encoding)

parts = []
unescaped = path.gsub(/%2e/i, dot).gsub(/%2f/i, slash).gsub(/%5c/i, backslash)
Expand Down
16 changes: 7 additions & 9 deletions rack-protection/spec/lib/rack/protection/path_traversal_spec.rb
Expand Up @@ -24,16 +24,14 @@
end
end

if "".respond_to?(:encoding) # Ruby 1.9+ M17N
context "PATH_INFO's encoding" do
before do
@app = Rack::Protection::PathTraversal.new(proc { |e| [200, {'Content-Type' => 'text/plain'}, [e['PATH_INFO'].encoding.to_s]] })
end
context "PATH_INFO's encoding" do
before do
@app = Rack::Protection::PathTraversal.new(proc { |e| [200, {'Content-Type' => 'text/plain'}, [e['PATH_INFO'].encoding.to_s]] })
end

it 'should remain unchanged as ASCII-8BIT' do
body = @app.call({ 'PATH_INFO' => '/'.encode('ASCII-8BIT') })[2][0]
expect(body).to eq('ASCII-8BIT')
end
it 'should remain unchanged as ASCII-8BIT' do
body = @app.call({ 'PATH_INFO' => '/'.encode('ASCII-8BIT') })[2][0]
expect(body).to eq('ASCII-8BIT')
end
end
end