From 1115703b7ccb6280a240454ab996128938c53b59 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 12 Apr 2019 22:29:34 +0200 Subject: [PATCH 1/2] Drop Ruby 1.8 compat code --- .../lib/rack/protection/path_traversal.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/rack-protection/lib/rack/protection/path_traversal.rb b/rack-protection/lib/rack/protection/path_traversal.rb index a6ca87f065..4e8c94ca95 100644 --- a/rack-protection/lib/rack/protection/path_traversal.rb +++ b/rack-protection/lib/rack/protection/path_traversal.rb @@ -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) From 0df3f3c115d58263740d7c55cc1ab57a1d44c611 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 12 Apr 2019 23:17:19 +0200 Subject: [PATCH 2/2] Drop Ruby 1.8 checks --- .../lib/rack/protection/path_traversal_spec.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rack-protection/spec/lib/rack/protection/path_traversal_spec.rb b/rack-protection/spec/lib/rack/protection/path_traversal_spec.rb index a4d52ff2c4..0e191cf2fc 100644 --- a/rack-protection/spec/lib/rack/protection/path_traversal_spec.rb +++ b/rack-protection/spec/lib/rack/protection/path_traversal_spec.rb @@ -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