~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/uri/common.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum, Daigo Moriwaki, Lucas Nussbaum
  • Date: 2011-07-25 20:27:20 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110725202720-9qfs7iam0ml7e1kc
Tags: 1.9.2.290-1
[ Daigo Moriwaki ]
* New upstream release.
* Removed debian/patches/110411_disable_osslv2.patch, which has been applied
  by the upstream.
* Added a patch: debian/patches/debian/patches/110716-bigdecimal,
  which was backported from the upstream (r30993)
  (CVE-2011-0188; Closes: 628450)

[ Lucas Nussbaum ]
* Build-depend on tcl-dev and tk-dev instead of {tcl,tk}8.4-dev.
* Update Lucas' email address.
* Add 110825-ossl-config.diff: backport changes to the OpenSSL
  extension to fix test failure.
* Add patch 110720_tcltk_disable_rpath.diff: disable rpath in tcltk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# = uri/common.rb
2
2
#
3
3
# Author:: Akira Yamada <akira@ruby-lang.org>
4
 
# Revision:: $Id: common.rb 30306 2010-12-23 10:49:00Z yugui $
 
4
# Revision:: $Id: common.rb 31799 2011-05-29 22:49:36Z yugui $
5
5
# License::
6
6
#   You can redistribute it and/or modify it under the same term as Ruby.
7
7
#
731
731
  # See URI.decode_www_form_component, URI.encode_www_form
732
732
  def self.encode_www_form_component(str)
733
733
    if TBLENCWWWCOMP_.empty?
 
734
      tbl = {}
734
735
      256.times do |i|
735
 
        TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
736
 
      end
737
 
      TBLENCWWWCOMP_[' '] = '+'
738
 
      TBLENCWWWCOMP_.freeze
 
736
        tbl[i.chr] = '%%%02X' % i
 
737
      end
 
738
      tbl[' '] = '+'
 
739
      begin
 
740
        TBLENCWWWCOMP_.replace(tbl)
 
741
        TBLENCWWWCOMP_.freeze
 
742
      rescue
 
743
      end
739
744
    end
740
745
    str = str.to_s
741
746
    if HTML5ASCIIINCOMPAT.include?(str.encoding)
755
760
  # See URI.encode_www_form_component, URI.decode_www_form
756
761
  def self.decode_www_form_component(str, enc=Encoding::UTF_8)
757
762
    if TBLDECWWWCOMP_.empty?
 
763
      tbl = {}
758
764
      256.times do |i|
759
765
        h, l = i>>4, i&15
760
 
        TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
761
 
        TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
762
 
        TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
763
 
        TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
764
 
      end
765
 
      TBLDECWWWCOMP_['+'] = ' '
766
 
      TBLDECWWWCOMP_.freeze
 
766
        tbl['%%%X%X' % [h, l]] = i.chr
 
767
        tbl['%%%x%X' % [h, l]] = i.chr
 
768
        tbl['%%%X%x' % [h, l]] = i.chr
 
769
        tbl['%%%x%x' % [h, l]] = i.chr
 
770
      end
 
771
      tbl['+'] = ' '
 
772
      begin
 
773
        TBLDECWWWCOMP_.replace(tbl)
 
774
        TBLDECWWWCOMP_.freeze
 
775
      rescue
 
776
      end
767
777
    end
768
778
    raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%\h\h|[^%]+)*\z/ =~ str
769
779
    str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)