Fix "URI.escape is obsolete" warnings on Ruby >= 1.9

This commit is contained in:
Erik Michaels-Ober 2012-12-01 18:04:07 -08:00
parent 496a6726ca
commit f67afa46fa
3 changed files with 13 additions and 5 deletions

View file

@ -17,11 +17,11 @@ module SimpleOAuth
end
def self.encode(value)
URI.encode(value.to_s, /[^a-z0-9\-\.\_\~]/i)
uri_parser.escape(value.to_s, /[^a-z0-9\-\.\_\~]/i)
end
def self.decode(value)
URI.decode(value.to_s)
uri_parser.unescape(value.to_s)
end
def self.parse(header)
@ -67,6 +67,10 @@ module SimpleOAuth
private
def self.uri_parser
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
end
def normalized_attributes
signed_attributes.sort_by{|k,v| k.to_s }.map{|k,v| %(#{k}="#{self.class.encode(v)}") }.join(', ')
end

View file

@ -8,6 +8,10 @@ end
require 'simple_oauth'
require 'rspec'
def uri_parser
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
end
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect

View file

@ -1,6 +1,6 @@
# encoding: utf-8
# encoding: utf-8
require 'spec_helper'
require 'helper'
describe SimpleOAuth::Header do
describe ".default_options" do
@ -27,7 +27,7 @@ describe SimpleOAuth::Header do
[' ', '!', '@', '#', '$', '%', '^', '&'].each do |character|
encoded = SimpleOAuth::Header.encode(character)
expect(encoded).not_to eq character
expect(encoded).to eq URI.encode(character, /.*/)
expect(encoded).to eq uri_parser.escape(character, /.*/)
end
end