Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dynamic input used in regular expression #2867

Merged
merged 7 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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