diff --git a/CHANGELOG.md b/CHANGELOG.md index ae6d070ce..a90ac995a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix error events missing a DSC when there's an active span ([#2408](https://github.com/getsentry/sentry-ruby/pull/2408)) - Verifies presence of client before adding a breadcrumb ([#2394](https://github.com/getsentry/sentry-ruby/pull/2394)) +- Fix `Net:HTTP` integration for non-ASCII URI's ([#2417](https://github.com/getsentry/sentry-ruby/pull/2417)) ## 5.19.0 diff --git a/sentry-ruby/lib/sentry/net/http.rb b/sentry-ruby/lib/sentry/net/http.rb index c769b4c3d..04820f3d5 100644 --- a/sentry-ruby/lib/sentry/net/http.rb +++ b/sentry-ruby/lib/sentry/net/http.rb @@ -66,7 +66,7 @@ def extract_request_info(req) # IPv6 url could look like '::1/path', and that won't parse without # wrapping it in square brackets. hostname = address =~ Resolv::IPv6::Regex ? "[#{address}]" : address - uri = req.uri || URI.parse("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}") + uri = req.uri || URI.parse(URI::DEFAULT_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) url = "#{uri.scheme}://#{uri.host}#{uri.path}" rescue uri.to_s result = { method: req.method, url: url } diff --git a/sentry-ruby/spec/sentry/net/http_spec.rb b/sentry-ruby/spec/sentry/net/http_spec.rb index 064c4f36c..6a6dbbf73 100644 --- a/sentry-ruby/spec/sentry/net/http_spec.rb +++ b/sentry-ruby/spec/sentry/net/http_spec.rb @@ -107,6 +107,22 @@ end end + it "supports non-ascii characters in the path" do + stub_normal_response + + uri = URI('http://example.com') + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new('/path?q=øgreyfoss&å=vær') + + transaction = Sentry.start_transaction + Sentry.get_current_scope.set_span(transaction) + + + response = http.request(request) + + expect(response.code).to eq("200") + end + it "adds sentry-trace header to the request header" do uri = URI("http://example.com/path") http = Net::HTTP.new(uri.host, uri.port)