Skip to content

Commit e3c71d1

Browse files
Address URI.escape obsolete warning
Prior to these changes, `URI.escape` would trigger a warning. Instead, this uses `Addressable::URI.escape` to maintain similar behavior, but without the warning. One difference between the two being how the `#` sign is handled. `URI.escape` escapes this character. `Addressable::URI.escape` does not. See this link for more information: https://stackoverflow.com/a/13059657 Co-authored-by: Daniel Colson <danieljamescolson@gmail.com>
1 parent 36fcf33 commit e3c71d1

File tree

5 files changed

+92
-5
lines changed

5 files changed

+92
-5
lines changed

docusign_esign.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
2929
s.add_runtime_dependency 'jwt', '~> 2.2', '>= 2.2.1'
3030
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
3131
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
32+
s.add_runtime_dependency 'addressable', '~> 2.7', '>= 2.7.0'
3233

3334
s.add_development_dependency 'rspec-mocks', '~> 3.8', '>= 3.8.0'
3435
s.add_development_dependency 'rspec-expectations', '~> 3.8', '>= 3.8.0'

lib/docusign_esign/client/api_client.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
=end
1111

12+
require 'addressable'
1213
require 'date'
1314
require 'json'
1415
require 'logger'
@@ -259,8 +260,8 @@ def sanitize_filename(filename)
259260
def build_request_url(path, opts)
260261
# Add leading and trailing slashes to path
261262
path = "/#{path}".gsub(/\/+/, '/')
262-
return URI.encode("https://" + self.get_oauth_base_path + path) if opts[:oauth]
263-
URI.encode(@config.base_url + path)
263+
return Addressable::URI.escape("https://" + self.get_oauth_base_path + path) if opts[:oauth]
264+
Addressable::URI.escape(@config.base_url + path)
264265
end
265266

266267
# Builds the HTTP request body

lib/docusign_esign/configuration.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
=end
1212

13-
require 'uri'
13+
require 'addressable'
1414

1515
module DocuSign_eSign
1616
class Configuration
@@ -169,7 +169,7 @@ def base_path=(base_path)
169169

170170
def base_url
171171
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
172-
URI.encode(url)
172+
Addressable::URI.escape(url)
173173
end
174174

175175
# Gets API key (with prefix if set).
@@ -200,4 +200,4 @@ def auth_settings
200200
}
201201
end
202202
end
203-
end
203+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require "docusign_esign"
2+
require "docusign_esign/client/api_client"
3+
4+
RSpec.describe DocuSign_eSign::ApiClient do
5+
describe "#build_request_url" do
6+
context "when the oauth option is set" do
7+
it "replaces unsafe characters with safe characters" do
8+
client = described_class.new
9+
client.oauth_base_path = "oauth.com"
10+
11+
url = client.build_request_url("/path^{}%<> #anchor", { oauth: true })
12+
13+
expect(url).to eq("https://oauth.com/path%5E%7B%7D%25%3C%3E%20#anchor")
14+
end
15+
16+
it "replaces multiple forward slashes with a single forward slash" do
17+
client = described_class.new
18+
client.oauth_base_path = "oauth.com"
19+
20+
url = client.build_request_url("//path", { oauth: true })
21+
22+
expect(url).to eq("https://oauth.com/path")
23+
end
24+
end
25+
26+
context "when the oauth option is not set" do
27+
it "replaces unsafe characters with safe characters" do
28+
config = instance_double("Configuration", base_url: "http://domain.com")
29+
client = described_class.new(config)
30+
31+
url = client.build_request_url("/path^{}%<> #anchor", { oauth: false })
32+
33+
expect(url).to eq("http://domain.com/path%5E%7B%7D%25%3C%3E%20#anchor")
34+
end
35+
36+
it "replaces multiple forward slashes with a single forward slash" do
37+
config = instance_double("Configuration", base_url: "http://domain.com")
38+
client = described_class.new(config)
39+
40+
url = client.build_request_url("//path", { oauth: false })
41+
42+
expect(url).to eq("http://domain.com/path")
43+
end
44+
end
45+
end
46+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "docusign_esign"
2+
require "docusign_esign/configuration"
3+
4+
RSpec.describe DocuSign_eSign::Configuration do
5+
describe "#base_url" do
6+
it "replaces unsafe characters with safe characters" do
7+
configuration = DocuSign_eSign::Configuration.new
8+
configuration.scheme = "https"
9+
configuration.host = "www.domain.com"
10+
configuration.base_path = "/base/path^{}%<> #anchor"
11+
12+
base_url = configuration.base_url
13+
14+
expect(base_url).to eq("https://www.domain.com/base/path%5E%7B%7D%25%3C%3E%20#anchor")
15+
end
16+
17+
it "replaces multiple forward slashes with a single forward slash" do
18+
configuration = DocuSign_eSign::Configuration.new
19+
configuration.scheme = "https"
20+
configuration.host = "www.domain.com"
21+
configuration.base_path = "//base/path"
22+
23+
base_url = configuration.base_url
24+
25+
expect(base_url).to eq("https://www.domain.com/base/path")
26+
end
27+
28+
it "strips the trailing forward slash" do
29+
configuration = DocuSign_eSign::Configuration.new
30+
configuration.scheme = "https"
31+
configuration.host = "www.domain.com"
32+
configuration.base_path = "/base/path/"
33+
34+
base_url = configuration.base_url
35+
36+
expect(base_url).to eq("https://www.domain.com/base/path")
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)