mirror of
https://github.com/samsonjs/simple_oauth.git
synced 2026-04-27 14:57:45 +00:00
Fix "URI.escape is obsolete" warnings on Ruby >= 1.9
This commit is contained in:
parent
496a6726ca
commit
f67afa46fa
3 changed files with 13 additions and 5 deletions
|
|
@ -17,11 +17,11 @@ module SimpleOAuth
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.encode(value)
|
def self.encode(value)
|
||||||
URI.encode(value.to_s, /[^a-z0-9\-\.\_\~]/i)
|
uri_parser.escape(value.to_s, /[^a-z0-9\-\.\_\~]/i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.decode(value)
|
def self.decode(value)
|
||||||
URI.decode(value.to_s)
|
uri_parser.unescape(value.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse(header)
|
def self.parse(header)
|
||||||
|
|
@ -67,6 +67,10 @@ module SimpleOAuth
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def self.uri_parser
|
||||||
|
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
||||||
|
end
|
||||||
|
|
||||||
def normalized_attributes
|
def normalized_attributes
|
||||||
signed_attributes.sort_by{|k,v| k.to_s }.map{|k,v| %(#{k}="#{self.class.encode(v)}") }.join(', ')
|
signed_attributes.sort_by{|k,v| k.to_s }.map{|k,v| %(#{k}="#{self.class.encode(v)}") }.join(', ')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ end
|
||||||
require 'simple_oauth'
|
require 'simple_oauth'
|
||||||
require 'rspec'
|
require 'rspec'
|
||||||
|
|
||||||
|
def uri_parser
|
||||||
|
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
||||||
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.expect_with :rspec do |c|
|
config.expect_with :rspec do |c|
|
||||||
c.syntax = :expect
|
c.syntax = :expect
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'helper'
|
||||||
|
|
||||||
describe SimpleOAuth::Header do
|
describe SimpleOAuth::Header do
|
||||||
describe ".default_options" do
|
describe ".default_options" do
|
||||||
|
|
@ -27,7 +27,7 @@ describe SimpleOAuth::Header do
|
||||||
[' ', '!', '@', '#', '$', '%', '^', '&'].each do |character|
|
[' ', '!', '@', '#', '$', '%', '^', '&'].each do |character|
|
||||||
encoded = SimpleOAuth::Header.encode(character)
|
encoded = SimpleOAuth::Header.encode(character)
|
||||||
expect(encoded).not_to eq character
|
expect(encoded).not_to eq character
|
||||||
expect(encoded).to eq URI.encode(character, /.*/)
|
expect(encoded).to eq uri_parser.escape(character, /.*/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue