Skip to content

Commit 2fd989f

Browse files
authored
Merge pull request #1370 from appsignal/fix-http-non-ascii-uri
Fix HTTP.rb when using non-ascii URIs
2 parents c181025 + fce0acd commit 2fd989f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: patch
3+
type: fix
4+
---
5+
6+
Fix an issue where the HTTP.rb gem integration would raise an error when a string containing non-ASCII characters is passed to the gem as the URL.

lib/appsignal/integrations/http.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Integrations
55
# @api private
66
module HttpIntegration
77
def request(verb, uri, opts = {})
8-
parsed_request_uri = uri.is_a?(URI) ? uri : URI.parse(uri.to_s)
8+
uri_module = defined?(HTTP::URI) ? HTTP::URI : URI
9+
parsed_request_uri = uri.is_a?(URI) ? uri : uri_module.parse(uri.to_s)
910
request_uri = "#{parsed_request_uri.scheme}://#{parsed_request_uri.host}"
1011

1112
Appsignal.instrument("request.http_rb", "#{verb.upcase} #{request_uri}") do

spec/lib/appsignal/integrations/http_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,18 @@ def to_s
9696
)
9797
end
9898

99-
it "parses a String object" do
99+
it "parses an HTTP::URI object" do
100+
stub_request(:get, "http://www.google.com")
101+
102+
HTTP.get(HTTP::URI.parse("http://www.google.com"))
103+
104+
expect(transaction).to include_event(
105+
"name" => "request.http_rb",
106+
"title" => "GET http://www.google.com"
107+
)
108+
end
109+
110+
it "parses a string" do
100111
stub_request(:get, "http://www.google.com")
101112

102113
HTTP.get("http://www.google.com")
@@ -106,6 +117,17 @@ def to_s
106117
"title" => "GET http://www.google.com"
107118
)
108119
end
120+
121+
it "parses a string with non-ascii characters" do
122+
stub_request(:get, "http://www.example.com/áéíóúãÔù")
123+
124+
HTTP.get("http://www.example.com/áéíóúãÔù")
125+
126+
expect(transaction).to include_event(
127+
"name" => "request.http_rb",
128+
"title" => "GET http://www.example.com"
129+
)
130+
end
109131
end
110132
end
111133
end

0 commit comments

Comments
 (0)