ruby-changes:19227
From: naruse <ko1@a...>
Date: Tue, 12 Apr 2011 19:20:59 +0900 (JST)
Subject: [ruby-changes:19227] Ruby:r31266 (trunk): * lib/uri/common.rb: avoid race condition. fixes #4572
naruse 2011-04-12 19:20:50 +0900 (Tue, 12 Apr 2011) New Revision: 31266 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31266 Log: * lib/uri/common.rb: avoid race condition. fixes #4572 Modified files: trunk/ChangeLog trunk/lib/uri/common.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31265) +++ ChangeLog (revision 31266) @@ -1,3 +1,7 @@ +Tue Apr 12 19:19:50 2011 NARUSE, Yui <naruse@r...> + + * lib/uri/common.rb: avoid race condition. fixes #4572 + Tue Apr 12 18:07:13 2011 TAKAO Kouji <kouji@t...> * ext/readline/extconf.rb: --disable-libedit to disable Index: lib/uri/common.rb =================================================================== --- lib/uri/common.rb (revision 31265) +++ lib/uri/common.rb (revision 31266) @@ -743,11 +743,16 @@ # 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| - TBLENCWWWCOMP_[i.chr] = '%%%02X' % i + tbl[i.chr] = '%%%02X' % i end - TBLENCWWWCOMP_[' '] = '+' - TBLENCWWWCOMP_.freeze + tbl[' '] = '+' + begin + TBLENCWWWCOMP_.replace(tbl) + TBLENCWWWCOMP_.freeze + rescue + end end str = str.to_s if HTML5ASCIIINCOMPAT.include?(str.encoding) @@ -767,15 +772,20 @@ # 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 - 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 + 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 - TBLDECWWWCOMP_['+'] = ' ' - TBLDECWWWCOMP_.freeze + 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/