diff --git a/lib/puma/rack/backports/uri/common_18.rb b/lib/puma/rack/backports/uri/common_18.rb index ca3a6360..bbe4fe07 100644 --- a/lib/puma/rack/backports/uri/common_18.rb +++ b/lib/puma/rack/backports/uri/common_18.rb @@ -7,22 +7,25 @@ # module URI - TBLENCWWWCOMP_ = {} # :nodoc: - 256.times do |i| - TBLENCWWWCOMP_[i.chr] = '%%%02X' % i + begin + TBLENCWWWCOMP_ = {} # :nodoc: + 256.times do |i| + TBLENCWWWCOMP_[i.chr] = '%%%02X' % i + end + TBLENCWWWCOMP_[' '] = '+' + TBLENCWWWCOMP_.freeze + TBLDECWWWCOMP_ = {} # :nodoc: + 256.times do |i| + h, l = i>>4, i&15 + TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr + end + TBLDECWWWCOMP_['+'] = ' ' + TBLDECWWWCOMP_.freeze + rescue Exception end - TBLENCWWWCOMP_[' '] = '+' - TBLENCWWWCOMP_.freeze - TBLDECWWWCOMP_ = {} # :nodoc: - 256.times do |i| - h, l = i>>4, i&15 - TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr - end - TBLDECWWWCOMP_['+'] = ' ' - TBLDECWWWCOMP_.freeze # Encode given +s+ to URL-encoded form data. # diff --git a/lib/puma/rack/backports/uri/common_192.rb b/lib/puma/rack/backports/uri/common_192.rb index 1a0522bf..a3cc4d1d 100644 --- a/lib/puma/rack/backports/uri/common_192.rb +++ b/lib/puma/rack/backports/uri/common_192.rb @@ -17,17 +17,20 @@ require 'uri/common' module URI - TBLDECWWWCOMP_ = {} unless const_defined?(:TBLDECWWWCOMP_) #:nodoc: - if TBLDECWWWCOMP_.empty? - 256.times do |i| - h, l = i>>4, i&15 - TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr + begin + TBLDECWWWCOMP_ = {} unless const_defined?(:TBLDECWWWCOMP_) #:nodoc: + if TBLDECWWWCOMP_.empty? + 256.times do |i| + h, l = i>>4, i&15 + TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr + end + TBLDECWWWCOMP_['+'] = ' ' + TBLDECWWWCOMP_.freeze end - TBLDECWWWCOMP_['+'] = ' ' - TBLDECWWWCOMP_.freeze + rescue Exception end def self.decode_www_form(str, enc=Encoding::UTF_8) diff --git a/lib/puma/rack/backports/uri/common_193.rb b/lib/puma/rack/backports/uri/common_193.rb index 2e582033..d4609d79 100644 --- a/lib/puma/rack/backports/uri/common_193.rb +++ b/lib/puma/rack/backports/uri/common_193.rb @@ -8,22 +8,26 @@ require 'uri/common' # Relevant commit: # https://github.com/ruby/ruby/commit/edb7cdf1eabaff78dfa5ffedfbc2e91b29fa9ca1 -module URI - 256.times do |i| - TBLENCWWWCOMP_[i.chr] = '%%%02X' % i - end - TBLENCWWWCOMP_[' '] = '+' - TBLENCWWWCOMP_.freeze - 256.times do |i| - h, l = i>>4, i&15 - TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr - TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr +module URI + begin + 256.times do |i| + TBLENCWWWCOMP_[i.chr] = '%%%02X' % i + end + TBLENCWWWCOMP_[' '] = '+' + TBLENCWWWCOMP_.freeze + + 256.times do |i| + h, l = i>>4, i&15 + TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr + TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr + end + TBLDECWWWCOMP_['+'] = ' ' + TBLDECWWWCOMP_.freeze + rescue Exception end - TBLDECWWWCOMP_['+'] = ' ' - TBLDECWWWCOMP_.freeze end # :startdoc: