From ca0ac3e3c9a554afaaa632f98d7e2e3f151d90f4 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 29 May 2011 22:49:36 +0000 Subject: [PATCH] merges r31266 from trunk into ruby_1_9_2. -- * lib/uri/common.rb: avoid race condition. fixes #4572 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31799 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ lib/uri/common.rb | 28 +++++++++++++++++++--------- version.h | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e70709e1b2..e61ec4d5d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Apr 12 19:19:50 2011 NARUSE, Yui + + * lib/uri/common.rb: avoid race condition. fixes #4572 + Tue Apr 12 10:37:39 2011 NAKAMURA Usaku * include/ruby/win32.h: VC doesn't have ftruncate() and others, but diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 00a543c9f2..ed8556c976 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -731,11 +731,16 @@ module URI # 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 + tbl[' '] = '+' + begin + TBLENCWWWCOMP_.replace(tbl) + TBLENCWWWCOMP_.freeze + rescue end - TBLENCWWWCOMP_[' '] = '+' - TBLENCWWWCOMP_.freeze end str = str.to_s if HTML5ASCIIINCOMPAT.include?(str.encoding) @@ -755,15 +760,20 @@ module URI # 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 + tbl['+'] = ' ' + begin + TBLDECWWWCOMP_.replace(tbl) + TBLDECWWWCOMP_.freeze + rescue end - TBLDECWWWCOMP_['+'] = ' ' - TBLDECWWWCOMP_.freeze end raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%\h\h|[^%]+)*\z/ =~ str str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc) diff --git a/version.h b/version.h index 989effc925..76d326ef92 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 226 +#define RUBY_PATCHLEVEL 227 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1