diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9f5179e208..88174dd4f3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -82,19 +82,19 @@ updates: versions: - '>= 4' - # - package-ecosystem: bundler - # directory: "/packages/ruby" - # schedule: - # interval: monthly - # allow: - # - dependency-type: production - # open-pull-requests-limit: 10 - # labels: - # - dependencies - # - ruby - # commit-message: - # prefix: chore(deps) - # prefix-development: chore(deps-dev) + - package-ecosystem: bundler + directory: '/packages/ruby' + schedule: + interval: monthly + allow: + - dependency-type: production + open-pull-requests-limit: 10 + labels: + - dependencies + - ruby + commit-message: + prefix: chore(deps) + prefix-development: chore(deps-dev) - package-ecosystem: composer directory: '/packages/php' diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 7a2fcabe89..786b69b6c9 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -34,9 +34,9 @@ jobs: matrix: ruby-version: # https://endoflife.date/ruby - - 2.7 # EOL: March 31st, 2023 - - '3.0' # EOL: March 31st, 2024 - - 3.1 # EOL: December 25th, 2025 + - 3.1 # EOL: March 31th, 2025 + - 3.2 # EOL: March 31th, 2026 + - 3.3 # EOL: March 31th, 2027 rack-version: # This will install the latest v2 - -v '>= 2.2' -v '< 3' diff --git a/packages/ruby/Gemfile.lock b/packages/ruby/Gemfile.lock index 95bb847563..286df5a0b8 100644 --- a/packages/ruby/Gemfile.lock +++ b/packages/ruby/Gemfile.lock @@ -8,69 +8,77 @@ PATH GEM remote: https://rubygems.org/ specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) - crack (0.4.3) - safe_yaml (~> 1.0.0) - diff-lcs (1.4.4) - hashdiff (1.0.1) - httparty (0.21.0) + bigdecimal (3.1.8) + crack (1.0.0) + bigdecimal + rexml + csv (3.3.0) + diff-lcs (1.5.1) + hashdiff (1.1.1) + httparty (0.22.0) + csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - json (2.6.2) - json-schema (2.8.1) - addressable (>= 2.4) + json (2.7.2) + json-schema (5.0.0) + addressable (~> 2.8) + language_server-protocol (3.17.0.3) mini_mime (1.1.5) - multi_xml (0.6.0) - parallel (1.22.1) - parser (3.1.2.1) + multi_xml (0.7.1) + bigdecimal (~> 3.1) + parallel (1.26.3) + parser (3.3.4.2) ast (~> 2.4.1) - public_suffix (4.0.6) - rack (2.2.3.1) - rack-test (1.1.0) - rack (>= 1.0, < 3) + racc + public_suffix (6.0.1) + racc (1.8.1) + rack (3.1.7) + rack-test (2.1.0) + rack (>= 1.3) rainbow (3.1.1) rake (12.3.3) - regexp_parser (2.5.0) - rexml (3.3.6) + regexp_parser (2.9.2) + rexml (3.3.5) strscan - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-core (3.9.2) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.2) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.1) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.3) - rubocop (1.36.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.65.1) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) - rubocop-performance (1.14.3) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-rspec (2.12.1) - rubocop (~> 1.31) - ruby-progressbar (1.11.0) - safe_yaml (1.0.5) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.1) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rspec (3.0.4) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) strscan (3.1.0) - unicode-display_width (2.2.0) - webmock (3.8.3) - addressable (>= 2.3.6) + unicode-display_width (2.5.0) + webmock (3.23.1) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) diff --git a/packages/ruby/lib/readme/http_request.rb b/packages/ruby/lib/readme/http_request.rb index 23a9190da1..736274ecb7 100644 --- a/packages/ruby/lib/readme/http_request.rb +++ b/packages/ruby/lib/readme/http_request.rb @@ -87,15 +87,9 @@ def headers def body if IS_RACK_V3 - body = @input.read - @input.rewind - body + read_body(@input) else - @request.body.rewind - content = @request.body.read - @request.body.rewind - - content + read_body(@request.body) end end @@ -134,5 +128,17 @@ def host_header 'Host' => @request.host }.compact end + + def read_body(io) + return '' if io.nil? + + io.rewind if io.respond_to?(:rewind) + content = io.read || '' + io.rewind if io.respond_to?(:rewind) + content + rescue => e + Readme::Metrics.logger.warn "Error reading request body: #{e.message}" + '' + end end end diff --git a/packages/ruby/readme-metrics.gemspec b/packages/ruby/readme-metrics.gemspec index 3e126fcf0a..0dd35192d7 100644 --- a/packages/ruby/readme-metrics.gemspec +++ b/packages/ruby/readme-metrics.gemspec @@ -26,6 +26,6 @@ Gem::Specification.new do |spec| # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_runtime_dependency 'httparty', '~> 0.18' - spec.add_runtime_dependency 'rack', '>= 2.2', '< 4' + spec.add_dependency 'httparty', '~> 0.18' + spec.add_dependency 'rack', '>= 2.2', '< 4' end diff --git a/packages/ruby/spec/readme/http_request_spec.rb b/packages/ruby/spec/readme/http_request_spec.rb index 357c2e25d5..3d3f740a6e 100644 --- a/packages/ruby/spec/readme/http_request_spec.rb +++ b/packages/ruby/spec/readme/http_request_spec.rb @@ -226,6 +226,16 @@ expect(request.body).to eq '[BODY]' expect(request.body).to eq '[BODY]' end + + it 'returns an empty string if an error occurs while reading the body' do + io = instance_double(StringIO, read: nil) + allow(io).to receive(:rewind).and_raise(StandardError.new('Test Error')) + + env = { 'rack.input' => io } + request = described_class.new(env) + + expect(request.body).to eq '' + end end describe '#parsed_form_data' do