From f9c360409254e5609e248eef8808d429ae40f05a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 2 Feb 2012 08:28:45 -0600 Subject: [PATCH] Update 1.9.2 stdlib to pick up URI lazy-init fix. --- lib/ruby/1.9/uri/common.rb | 43 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/lib/ruby/1.9/uri/common.rb b/lib/ruby/1.9/uri/common.rb index ed8556c9760..264fa053ed6 100644 --- a/lib/ruby/1.9/uri/common.rb +++ b/lib/ruby/1.9/uri/common.rb @@ -717,7 +717,22 @@ def self.regexp(schemes = nil) end 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 + HTML5ASCIIINCOMPAT = [Encoding::UTF_7, Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE] # :nodoc: @@ -730,18 +745,6 @@ def self.regexp(schemes = nil) # # See URI.decode_www_form_component, URI.encode_www_form def self.encode_www_form_component(str) - if TBLENCWWWCOMP_.empty? - tbl = {} - 256.times do |i| - tbl[i.chr] = '%%%02X' % i - end - tbl[' '] = '+' - begin - TBLENCWWWCOMP_.replace(tbl) - TBLENCWWWCOMP_.freeze - rescue - end - end str = str.to_s if HTML5ASCIIINCOMPAT.include?(str.encoding) str = str.encode(Encoding::UTF_8) @@ -759,22 +762,6 @@ def self.encode_www_form_component(str) # # See URI.encode_www_form_component, URI.decode_www_form def self.decode_www_form_component(str, enc=Encoding::UTF_8) - if TBLDECWWWCOMP_.empty? - tbl = {} - 256.times do |i| - h, l = i>>4, i&15 - tbl['%%%X%X' % [h, l]] = i.chr - tbl['%%%x%X' % [h, l]] = i.chr - tbl['%%%X%x' % [h, l]] = i.chr - tbl['%%%x%x' % [h, l]] = i.chr - end - tbl['+'] = ' ' - begin - TBLDECWWWCOMP_.replace(tbl) - TBLDECWWWCOMP_.freeze - rescue - end - end raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%\h\h|[^%]+)*\z/ =~ str str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc) end