Skip to content

Commit

Permalink
Merge pull request #1370 from appsignal/fix-http-non-ascii-uri
Browse files Browse the repository at this point in the history
Fix HTTP.rb when using non-ascii URIs
  • Loading branch information
unflxw authored Jan 22, 2025
2 parents c181025 + fce0acd commit 2fd989f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changesets/fix-http-rb-integration-for-non--ascii-urls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: fix
---

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.
3 changes: 2 additions & 1 deletion lib/appsignal/integrations/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Integrations
# @api private
module HttpIntegration
def request(verb, uri, opts = {})
parsed_request_uri = uri.is_a?(URI) ? uri : URI.parse(uri.to_s)
uri_module = defined?(HTTP::URI) ? HTTP::URI : URI
parsed_request_uri = uri.is_a?(URI) ? uri : uri_module.parse(uri.to_s)
request_uri = "#{parsed_request_uri.scheme}://#{parsed_request_uri.host}"

Appsignal.instrument("request.http_rb", "#{verb.upcase} #{request_uri}") do
Expand Down
24 changes: 23 additions & 1 deletion spec/lib/appsignal/integrations/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ def to_s
)
end

it "parses a String object" do
it "parses an HTTP::URI object" do
stub_request(:get, "http://www.google.com")

HTTP.get(HTTP::URI.parse("http://www.google.com"))

expect(transaction).to include_event(
"name" => "request.http_rb",
"title" => "GET http://www.google.com"
)
end

it "parses a string" do
stub_request(:get, "http://www.google.com")

HTTP.get("http://www.google.com")
Expand All @@ -106,6 +117,17 @@ def to_s
"title" => "GET http://www.google.com"
)
end

it "parses a string with non-ascii characters" do
stub_request(:get, "http://www.example.com/áéíóúãÔù")

HTTP.get("http://www.example.com/áéíóúãÔù")

expect(transaction).to include_event(
"name" => "request.http_rb",
"title" => "GET http://www.example.com"
)
end
end
end
end

0 comments on commit 2fd989f

Please sign in to comment.