Skip to content

Commit

Permalink
Merge pull request #407 from dayflower/spec_utils
Browse files Browse the repository at this point in the history
Use backport of URI module even on ruby 1.9.2-p320
  • Loading branch information
tenderlove committed Jul 15, 2012
2 parents edc8b92 + f496e9b commit e4172e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
41 changes: 11 additions & 30 deletions lib/rack/backports/uri/common_192.rb
Expand Up @@ -17,21 +17,18 @@
require 'uri/common'

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
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

def self.decode_www_form(str, enc=Encoding::UTF_8)
return [] if str.empty?
Expand All @@ -46,22 +43,6 @@ def self.decode_www_form(str, enc=Encoding::UTF_8)
end

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
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/utils.rb
Expand Up @@ -9,7 +9,7 @@

if major == 1 && minor < 9
require 'rack/backports/uri/common_18'
elsif major == 1 && minor == 9 && patch == 2 && RUBY_PATCHLEVEL < 318 && RUBY_ENGINE != 'jruby'
elsif major == 1 && minor == 9 && patch == 2 && RUBY_PATCHLEVEL <= 320 && RUBY_ENGINE != 'jruby'
require 'rack/backports/uri/common_192'
elsif major == 1 && minor == 9 && patch == 3 && RUBY_PATCHLEVEL < 125
require 'rack/backports/uri/common_193'
Expand Down
1 change: 1 addition & 0 deletions test/spec_utils.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
require 'rack/utils'
require 'rack/mock'
require 'timeout'

describe Rack::Utils do

Expand Down

0 comments on commit e4172e7

Please sign in to comment.