Skip to content

Commit

Permalink
Merge pull request #2867 from DataDog/remove-dynamic-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Jun 21, 2023
2 parents bdd22a4 + ba6caf0 commit 09033a7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
25 changes: 25 additions & 0 deletions lib/datadog/core/backport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Datadog
module Core
# This module is used to provide features from Ruby 2.5+ to older Rubies
module BackportFrom25
module_function

if ::String.method_defined?(:delete_prefix)
def string_delete_prefix(string, prefix)
string.delete_prefix(prefix)
end
else
def string_delete_prefix(string, prefix)
prefix = prefix.to_s
if string.start_with?(prefix)
string[prefix.length..-1] || raise('rbs-guard: String#[] is non-nil as `prefix` is guaranteed present')
else
string.dup
end
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/datadog/tracing/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'date'

require_relative '../../../core/environment/variable_helpers'
require_relative '../../../core/backport'
require_relative '../../client_ip'
require_relative '../../metadata/ext'
require_relative '../../propagation/http'
Expand Down Expand Up @@ -304,7 +305,7 @@ def parse_url(env, original_env)
else
# normally REQUEST_URI starts at the path, but it
# might contain the full URL in some cases (e.g WEBrick)
request_uri.sub(/^#{base_url}/, '')
Datadog::Core::BackportFrom25.string_delete_prefix(request_uri, base_url)
end

base_url + fullpath
Expand Down
7 changes: 7 additions & 0 deletions sig/datadog/core/backport.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Datadog
module Core
module BackportFrom25
def self?.string_delete_prefix: (::String string, ::String prefix) -> ::String
end
end
end

0 comments on commit 09033a7

Please sign in to comment.